我正在寻找任何帮助。我已经设置了 gitblit,我使用了一个稍微修改过的 groovy hooks 脚本版本。我需要一个将头部署到文件夹的钩子脚本,然后可以将其用作 WAMP 中该站点的 webroot。基本上,更改将被推送到 gitblit,脚本会将这些更改部署到我们的开发服务器上,无需任何人工干预。我在 subversion 上工作,在作为 webroot 的工作副本上进行简单的 svn 更新。Gitblit 似乎并不那么容易。
如果克隆文件夹已经存在,我希望它在主服务器上执行拉取命令。克隆代码一切正常,并成功创建了 repos 的克隆。但是当我推送更多更改并且克隆存在时,它会引发此错误:
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 )