GitBlit groovy钩子脚本PullCommand无法正常工作

时间:2014-03-12 13:13:05

标签: git groovy jgit gitblit

我正在寻找任何帮助。我有gitblit设置,我使用了一个groovy钩子脚本的略微修改版本。我需要一个钩子脚本,将头部署到一个文件夹,然后可以在WAMP中用作该站点的webroot。基本上,更改将被推送到gitblit,脚本将在我们的开发服务器上部署这些更改,而无需任何手动干预。我有这个工作在subversion上,在工作副本上有一个简单的svn更新作为webroot。 Gitblit似乎并不那么容易。

如果克隆文件夹已经存在,我希望它在主服务器上执行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 )

1 个答案:

答案 0 :(得分: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}")