public boolean gitPull(RunnerObj runnerObject, String User, String Password, String branch) throws IOException, WrongRepositoryStateException,
InvalidConfigurationException, InvalidRemoteException, CanceledException, RefNotFoundException, RefNotAdvertisedException, NoHeadException,
TransportException, GitAPIException, InterruptedException {
try {
String projectPath = runnerObject.getScrDir();
File projectDirectory = new File (projectPath);
Git git = Git.open(projectDirectory);
StoredConfig config = git.getRepository().getConfig();
config.setBoolean( "http", null, "sslVerify", false );
config.save();
UsernamePasswordCredentialsProvider user = new UsernamePasswordCredentialsProvider( User, Password);
// Fetch
log.debug("Fetching...");
git.fetch().setCredentialsProvider(user).call();
// Switch branch to expected branch
boolean isExpectedBranch = getCurrentBranch(branch, projectPath);
// if (needToStash(projectPath)) {
log.debug("Stashing ...");
gitStash(projectPath);
// }
//Delete Index.lock
log.debug("Delete index.lock in .git folder if exists");
deleteIndexLock(runnerObject.getScrDir() + File.separator + ".git" + File.separator + "index.lock");
if (isExpectedBranch) {
log.debug("Current branch is " + branch);
} else {
log.debug("Switch branch to " + branch);
if (!branchIsExist(branch, projectPath)) {
log.debug("Create new " + branch + " local branch");
git.checkout().setCreateBranch(true).setName(branch).setStartPoint("remotes/origin/" + branch).call(); // create and switch to expected branch
} else {
log.debug("Before");
git.checkout().setName(branch).setStartPoint("remotes/origin/" + branch).call();
log.debug("After");
}
}
// git pull --rebase
// PullResult result = git.pull().setCredentialsProvider(user).setRemoteBranchName(branch).setRebase(true).call();
log.debug("Rebase local " + branch + " on to remotes/" + branch );
RebaseResult rebaseResult = git.rebase().setUpstream(branch).call();
switch (rebaseResult.getStatus()) {
case STOPPED:
log.error("Merge conflict");
git.rebase().setOperation(Operation.ABORT).call();
throw new RuntimeException("Pull unsuccessful cause of " + rebaseResult.getStatus());
case OK:
case UP_TO_DATE:
case FAST_FORWARD:
log.debug("Rebase remotes " + branch + " to local successfully");
PullResult result = git.pull().setCredentialsProvider(user).setRemoteBranchName(branch).call();
if (result.isSuccessful()) {
log.debug("Pull successfully");
return true;
} else {
log.error("Pull unsuccessfully " + result.toString());
return false;
}
default:
git.rebase().setOperation(Operation.ABORT).call();
throw new RuntimeException("Pull unsuccessful cause of " + rebaseResult.getStatus());
}
} catch (IndexOutOfBoundsException e) {
log.debug("" + e);
return false;
}
}
我用jgit把代码拉到远程pc(windows操作系统)上,我已经把它们注解掉了 git.fetch()
. 当我运行tool.jar时,我得到了下面的trigger.log文本,它永远挂在“fetching…”上,但是如果我注解掉git.fecth(仅),git.pull()工作正常,那么stashing仍然可以正常工作
你们都知道这个案子吗?
谢谢您
日志在“正在获取…”时停止,不再运行,直到2020-11-26 22:27:05 debug jsystemtrigger:91 - jar目录:c:\trigger 2020-11-26 22:27:05 debug jsystemtrigger:141 - 删除日志文件夹2020-11-26 22:27:07 debug jsyst中的所有日志文件emtrigger:145 - 删除index.lock-in.git文件夹(如果存在)2020-11-26 22:27:07调试fs:532-readpipe[git,--版本],c:\program files\git\cmd 2020-11-26 22:27:07 debug fs:555-readpipe可能返回'git version 2.7.4.windows.1'2020-11-26 22:27:07 debug fs:556-剩余输出:
2020-11-26 22:27:07 debug fs:532-readpipe[git,config,--system,--edit],c:\program files\git\cmd 2020-11-26 22:27:07 debug fs:555-readpipe可能返回'c:/program files/git/mingw64/etc/gitconfig'2020-11-26 22:27:07 debug fs:556-剩余输出:
2020-11-26 22:27:07调试jsystemtrigger:1550 - 当前分支为:develope 2020-11-26 22:27:07 debug jsystemtrigger:1439 - 正在获取。。。
暂无答案!
目前还没有任何答案,快来回答吧!