当推送不可能时,JGit 推送不会失败
JGit push won't fail when push is impossible
我正在尝试使用 JGit 将本地存储库推送到 github 存储库:
String remote = "https://token@github.com/me/foo";
Repository repository = buildLocalRepository();
try (Git git = new Git(repository)) {
git.push()
.setCredentialsProvider(new UsernamePasswordCredentialsProvider("token", ""))
.setRemote(remote)
.call();
}
但是当远程存储库历史不同时(因此无法推送)它既不会失败也不会触及远程存储库(幸运的是)。有什么帮助吗?
谢谢
您似乎希望抛出异常;根据 Javadoc,被拒绝的 refs 不构成异常。相反,PushCommand.call()
returns 一个 PushResult
对象的列表,您可以检查它以查看每个请求的 ref 更新的状态。
我正在尝试使用 JGit 将本地存储库推送到 github 存储库:
String remote = "https://token@github.com/me/foo";
Repository repository = buildLocalRepository();
try (Git git = new Git(repository)) {
git.push()
.setCredentialsProvider(new UsernamePasswordCredentialsProvider("token", ""))
.setRemote(remote)
.call();
}
但是当远程存储库历史不同时(因此无法推送)它既不会失败也不会触及远程存储库(幸运的是)。有什么帮助吗? 谢谢
您似乎希望抛出异常;根据 Javadoc,被拒绝的 refs 不构成异常。相反,PushCommand.call()
returns 一个 PushResult
对象的列表,您可以检查它以查看每个请求的 ref 更新的状态。