[英]JGit sets git: URI instead of https: for remote on CircleCI
我有以下代碼(請參閱有關正在發生的事情的評論):
// Clone repository from GitHub into a local directory.
Git git = Git.cloneRepository()
.setBranch("gh-pages")
.setURI("https://github.com/RAnders00/KayonDoc.git")
.setDirectory(new File("/home/ubuntu/KayonDoc"))
.call();
// Print out remotes in config from JGit
Config config = git.getRepository().getConfig();
config.getSubsections("remote").forEach(it -> {
System.out.println(config.getString("remote", it, "url"));
});
// Prints https://github.com/RAnders00/KayonDoc.git
// Everything seems OK
// You could perform some changes to the repository here...
// Push changes to origin
git.push()
.setCredentialsManager(new UsernamePasswordCredentialsProvider("RAnders00", "hunter2"))
.call();
// Throws exception (look below)
Caught: org.eclipse.jgit.api.errors.TransportException: git@github.com:RAnders00/KayonDoc.git: push not permitted
org.eclipse.jgit.api.errors.TransportException: git@github.com:RAnders00/KayonDoc.git: push not permitted
at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:164)
at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:80)
at <your class> (YourClass.java:?)
Caused by: org.eclipse.jgit.errors.TransportException: git@github.com:RAnders00/KayonDoc.git: push not permitted
at org.eclipse.jgit.transport.BasePackPushConnection.noRepository(BasePackPushConnection.java:176)
at org.eclipse.jgit.transport.BasePackConnection.readAdvertisedRefsImpl(BasePackConnection.java:200)
at org.eclipse.jgit.transport.BasePackConnection.readAdvertisedRefs(BasePackConnection.java:178)
at org.eclipse.jgit.transport.TransportGitSsh$SshPushConnection.<init>(TransportGitSsh.java:341)
at org.eclipse.jgit.transport.TransportGitSsh.openPush(TransportGitSsh.java:166)
at org.eclipse.jgit.transport.PushProcess.execute(PushProcess.java:154)
at org.eclipse.jgit.transport.Transport.push(Transport.java:1200)
at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:157)
... 3 more
JGit將git:
url保存到.git/FETCH_HEAD
文件中,該文件隨后用於推送。 由於git:
protocol不支持身份驗證,因此我無法推送到遠程並且進程失敗。
.git/config
文件包含遠程的正確https:
URI(這就是代碼打印https:
URI的原因)。
我的問題是:
我該怎么做才能使JGit正確設置https:
URI
(這會讓我再次推)?
這個問題只出現在一個非常特殊的環境中(在CircleCI上,一個Ubuntu 12.04.2 LTS虛擬盒子) - 它不能在15.10,14.04 LTS和12.04.2 LTS新的ubuntu發行版上重現,而且不能在Windows上重現。
重現問題的最簡單方法是創建一個虛擬GitHub存儲庫,然后開始在CircleCI上構建您的虛擬項目,然后使用SSH重新運行您的第一個構建。 然后,您有30分鍾的SSH時間將任何groovy / java文件上傳到該框。 30分鍾后,盒子將被強行關閉。
如果我在克隆到的目錄中使用git remote -v
,我得到:(這指出了確實使用了git:
URI的事實)
origin git@github.com:RAnders00/KayonDoc.git (fetch)
origin git@github.com:RAnders00/KayonDoc.git (push)
看起來你已經定義了
Git提供了一種使用以下配置重寫URL的方法:
git config --global url."git://".insteadOf https://
要驗證是否已設置它,請檢查存儲庫的配置:
git config --list
您將在輸出中看到以下行:
url.git://.insteadof=https://
您還可以檢查.gitconfig
文件以驗證配置文件中沒有此條目
[url "git://"]
insteadOf = https://
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.