GitBlit groovy钩子脚本PullCommand不工作

GitBlit groovy钩子脚本PullCommand不工作,git,groovy,jgit,gitblit,Git,Groovy,Jgit,Gitblit,我正在寻求任何帮助。我已经设置了gitblit,我使用了groovy钩子脚本的一个稍加修改的版本。我需要一个钩子脚本,将头部部署到一个文件夹中,然后在WAMP中将其用作该站点的webroot。基本上,更改将被推送到gitblit,脚本将在开发服务器上部署这些更改,而无需任何手动干预。我在subversion上做了这项工作,在webroot的工作副本上做了一个简单的svn更新。Gitblit似乎没那么容易 如果克隆文件夹已经存在,我希望它在主机上执行Pull命令。克隆代码全部正常工作,并成功创建了

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

如果克隆文件夹已经存在,我希望它在主机上执行Pull命令。克隆代码全部正常工作,并成功创建了repo的克隆。但当我推送更多更改,并且克隆存在时,它会抛出以下错误:

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 )

感谢@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}")

感谢@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}")

感谢@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}")

感谢@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}")


哪一行抛出了错误?在
Git
中没有
static
pull
方法,它是一个,所以您需要一个指向存储库的
Git
实例。应该这样做。。。可能是
newgit(newfilerepository(destinationFolder)).pull()
?没有试过这些,所以这只是猜测;-)我猜是
org.eclipse.jgit.internal.storage.file.FileRepository
。也就是说它应该指向
.git
文件夹,我想。。。你犯了什么错误?对不起,我现在对这件事不了解。。。也许可以删除此内容,并提出有关此问题的新问题?祝你好运哪一行抛出了错误?在
Git
中没有
static
pull
方法,它是一个,所以您需要一个指向存储库的
Git
实例。应该这样做。。。可能是
newgit(newfilerepository(destinationFolder)).pull()
?没有试过这些,所以这只是猜测;-)我猜是
org.eclipse.jgit.internal.storage.file.FileRepository
。也就是说它应该指向
.git
文件夹,我想。。。你犯了什么错误?对不起,我现在对这件事不了解。。。也许可以删除此内容,并提出有关此问题的新问题?祝你好运哪一行抛出了错误?在
Git
中没有
static
pull
方法,它是一个,所以您需要一个指向存储库的
Git
实例。应该这样做。。。可能是
newgit(newfilerepository(destinationFolder)).pull()
?没有试过这些,所以这只是猜测;-)我猜是
org.eclipse.jgit.internal.storage.file.FileRepository
。也就是说它应该指向
.git
文件夹,我想。。。你犯了什么错误?对不起,我现在对这件事不了解。。。也许可以删除此内容,并提出有关此问题的新问题?祝你好运哪一行抛出了错误?在
Git
中没有
static
pull
方法,它是一个,所以您需要一个指向存储库的
Git
实例。应该这样做。。。可能是
newgit(newfilerepository(destinationFolder)).pull()
?没有试过这些,所以这只是猜测;-)我猜是
org.eclipse.jgit.internal.storage.file.FileRepository
。也就是说它应该指向
.git
文件夹,我想。。。你犯了什么错误?对不起,我现在对这件事不了解。。。也许可以删除此内容,并提出有关此问题的新问题?祝你好运嘿@brighterdean,使用fetch和reset origin/master可以克隆您的repo,使用merge可以保留本地更改(但也许您想要?)@brighterdean我有两个私有Gitblit服务器A和B,我需要保持B与A同步,我发现可以使用Groovy Posh钩子,但我不知道在哪里配置这个钩子以及如何配置?,感谢您的帮助,谢谢@brighterdean,使用fetch和reset origin/master可以克隆您的repo,使用merge可以保留本地更改(但也许您需要?)@brighterdean我有两个私有Gitblit服务器A和B,我需要保持B与A的同步,我发现使用Groovy Posh hook是可能的,但是我不知道在哪里配置这个钩子以及如何配置?@brighterdean,如果有任何帮助,我们将不胜感激,感谢@brighterdean,使用fetch和reset origin/master保持您的repo克隆,使用merge将保持本地更改(但可能您想要吗?@brighterdean我有两个私有Gitblit服务器A和B,我需要保持B与A同步,我发现使用Groovy Posh钩子是可行的,但我不知道在哪里配置这个钩子以及如何配置?,任何帮助都将不胜感激,谢谢@brighterdean,使用fetch和reset origin/master可以克隆您的repo,使用merge可以保留本地更改(但可能您想要吗?)@brighterdean我有两个私有Gitblit服务器A和B,我需要使B与A保持同步,我发现使用Groovy Posh钩子是可行的,但我不知道在哪里配置这个钩子以及如何配置?如果您有任何帮助,我们将不胜感激,谢谢