2014-03-12 59 views
0

我在找任何幫助。我有gitblit設置,我使用了groovy鉤子腳本之一的稍微修改版本。我需要一個將頭部部署到一個文件夾的鉤子腳本,然後它可以用作WAMP中該網站的webroot。基本上,這些更改將推到gitblit,腳本將在我們的開發服務器上部署這些更改,而無需任何手動干預。我有一個工作副本作爲webroot一個簡單的svn更新在顛覆工作。 Gitblit似乎並不那麼容易。GitBlit groovy鉤子腳本PullCommand不工作

如果克隆文件夾已經存在,我希望它在主服務器上執行Pull命令。克隆代碼都可以正常工作併成功創建回購的克隆。但後來當我把更多的變化,並克隆存在,它拋出這個錯誤:

groovy.lang.MissingMethodException: No signature of method: static org.eclipse.j 
git.api.Git.pull() is applicable for argument types:() values: [] 

完整的Groovy腳本如下。我對groovy有一點小小的興趣,並且多年來一直沒有正確使用java,所以任何幫助都會給你上帝般的地位。提前致謝。

import com.gitblit.GitBlit 
import com.gitblit.Keys 
import com.gitblit.models.RepositoryModel 
import com.gitblit.models.TeamModel 
import com.gitblit.models.UserModel 
import com.gitblit.utils.JGitUtils 
import com.gitblit.utils.StringUtils 
import java.text.SimpleDateFormat 
import org.eclipse.jgit.lib.Repository 
import org.eclipse.jgit.lib.Config 
import org.eclipse.jgit.api.*; 
import org.eclipse.jgit.api.errors.*; 
import org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode; 
import org.eclipse.jgit.lib.Repository; 
import org.eclipse.jgit.util.FileUtils 
import org.slf4j.Logger 

// Indicate we have started the script 
logger.info("Deploying website (In Repository ${repository.name}) for ${user.username}") 

def rootFolder = 'C:/Program Files/wamp/www/git-repositories' 
def bare = false 
def cloneAllBranches = true 
def cloneBranch = 'refs/heads/master' 
def includeSubmodules = true 

def repoName = repository.name 
def destinationFolder = new File(rootFolder, StringUtils.stripDotGit(repoName)) 
def srcUrl = 'file://' + new File(gitblit.getRepositoriesFolder(), repoName).absolutePath 

// if there is already a clone 
if (destinationFolder.exists()) { 
    PullCommand cmd = Git.pull(); 
} 
else 
{ 
    // clone the repository 
    logger.info("cloning ${srcUrl} to ${destinationFolder}") 
    CloneCommand cmd = Git.cloneRepository(); 
    cmd.setBare(bare) 
    if (cloneAllBranches) 
     cmd.setCloneAllBranches(true) 
    else 
     cmd.setBranch(cloneBranch) 
    cmd.setCloneSubmodules(includeSubmodules) 
    cmd.setURI(srcUrl) 
    cmd.setDirectory(destinationFolder) 
    Git git = cmd.call(); 
    git.repository.close() 

    // report clone operation success back to pushing Git client 
    clientLogger.info("${repoName} cloned to ${destinationFolder}") 
} 

更新:有沒有更多的錯誤,但沒有變化似乎揪成克隆回購:

logger.info("Development clone already exists, pulling changes...") 

def cloneLocation = rootFolder + "/" + StringUtils.stripDotGit(repoName) + ""; 

FileRepository repo = new FileRepository("C:/Program Files/wamp/www/git-repositories/brightercreative.dev"); 

Git git = new Git(repo); 

logger.info("Pulling changes from "+cloneLocation) 

git.pull(); 

git.repository.close(); 

logger.info("Pulled changes "+cloneLocation) 
+0

哪一行會拋出錯誤? –

+0

Woops,我添加了錯誤的代碼,此刻,它只是刪除克隆,然後重新克隆它。這很好,但對於像我們這樣的大型項目來說,這需要很長時間。我刪除了「FileUtils.delete(destinationFolder,FileUtils.RECURSIVE)」並添加了PullCommand cmd = Git.pull();線。 – verenion

+0

PullCommand cmd = Git.pull();是失敗的路線。 – verenion

回答

3

感謝@tim_yates就這個幫助。終於明白了這一點。

def cloneLocation = rootFolder + "/" + StringUtils.stripDotGit(repoName) + ""; 

// create the file repository object 
FileRepository repo = new FileRepository("C:/myclonedrepos/.git"); 

// use the repository object to create a git object 
Git git = new Git(repo); 

// create a pull command 
PullCommand pullCmd = git.pull(); 

// call the pull command 
pullCmd.call(); 

git.repository.close(); 

logger.info("Pulled changes "+cloneLocation) 

// report clone operation success back to pushing Git client 
clientLogger.info("${repoName} pulled to ${destinationFolder}") 
+0

嘿@brighterdean,使用獲取和重置原點/主要保持您的回購克隆,使用合併將保持本地更改(但也許你想要嗎?) –

+0

https://gist.github.com/tom-power/b94d0648f2571d33745a –

+0

@brighterdean 我有兩個私人Gitblit服務器A和B,我需要保持B與A同步,我發現它使用Groovy Posh鉤,但我不知道在哪裏配置這個胡克和如何?,任何幫助將不勝感激,謝謝 – HybrisFreelance