[英]Custom git push ant task wont work in JGit
我正在嘗試使用JGit完成我的自定義git-push ant任務,該任務應將指定的分支推送到遠程存儲庫,但似乎無法正常工作。
這是我執行任務的Java代碼:
public void setRepository(String repository) {
this.repository = repository;
}
public void setPassword(String password) {
this.password = password;
}
public void setUsername(String username) {
this.username = username;
}
public void setUri(String uri) {
this.uri = uri;
}
public void setBranch(String branch) {
this.branch = branch;
}
public void execute() throws BuildException {
try{
Git git = Git.open(new File(repository));
CredentialsProvider cp = new UsernamePasswordCredentialsProvider(username, password);
RefSpec spec = new RefSpec("refs/heads/" + branch + ":refs/heads/" + branch);
PushCommand pushCommand = git.push();
pushCommand.setCredentialsProvider(cp).setRemote(uri).setForce(true).setRefSpecs(spec).call();
}catch (Exception e) {
log(e, Project.MSG_ERR);
throw new BuildException("Could not push repository: " + e.getMessage(), e);
}
這是Apache ant構建文件中的代碼行:
<gitpush
repository="./myrepo"
uri="ssh://username@host.com/repo/project.git"
branch="mybranch"
password="77CJr2xr" />
我創建一個新分支並嘗試運行此任務。 該任務無例外運行,但對遠程存儲庫沒有影響。 我是git的新手,所以這可能真是愚蠢的錯誤。 我對RefSpec做錯了嗎?
如果有人在您上次獲取或克隆之后並在嘗試推送之前將推送到同一分支,則返回denying non-fast-forward refs/heads/...
的錯誤消息。
you> git clone ...
bob> git clone ...
bob> git commit
bob> git push
you> git commit
you> git push <<-- error: denying non-fast-forward
遠程存儲庫的receive.denyNonFastForwards
配置設置控制是否允許非快速更新。 通常這是不允許的,因為這會更改遠程存儲庫的歷史記錄。 在上面的示例中,Bob的提交將丟失。
搜索“ git push錯誤拒絕非快進”以了解更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.