2015-11-20 10 views
15

上のリモートのために私は(何が起こっているかについてコメントを参照してください)次のコードを持っている:JGitはgitのを設定します:URIではなくHTTPSを: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: [email protected]:RAnders00/KayonDoc.git: push not permitted 
org.eclipse.jgit.api.errors.TransportException: [email protected]: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: [email protected]: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/FETCH_HEADgit: URLを保存していますこれはプッシュに使用されます。git:プロトコルは認証をサポートしていないため、リモートにプッシュすることができず、プロセスは失敗します。

.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。

問題を再現する最も簡単な方法は、createにダミーのGitHubリポジトリを作成し、start building CircleCI上にダミープロジェクトを作成し、最初のビルドをSSHで再実行することです。 Groovy/JavaファイルをボックスにアップロードするSSH時間は30分です。 30分後、ボックスは強制的にシャットダウンされます。


私はこれが中にクローニングしたディレクトリにgit remote -vを使用している場合は、私が取得する:あなたが定義されているように見えます(これgit:のURIが実際に使用されているという事実に私を指す)

origin [email protected]:RAnders00/KayonDoc.git (fetch) 
origin [email protected]:RAnders00/KayonDoc.git (push) 
+0

WindowsではhttpsのURLがそのまま残っていることを確認できます。 Linuxでこれが当てはまらない場合は、バグのように思えますが、私は[bugzillaをファイルします](https://eclipse.org/jgit/support/)です。 –

+0

はい、コードを簡単に見ても明らかな理由はありませんでした。設定は、設定したURLから構成されています。たぶんあなたのコードでAPIのいくつかの不正な使用法を排除するためにあなたのマシン上でJGitに迅速なデバッグを行うことができます... – centic

+0

私はあなただったら、私はちょうどsshのキーでgitプロトコルを使用したい – AdamSkywalker

答えて

2

Gitリポジトリを書き換え

URLは、以下の設定でURLを書き換えるための方法を提供します:

git config --global url."git://".insteadOf https:// 

あなたはそれがあなたのリポジトリの設定をチェックしているかどうかを確認するために:あなたはまた、あなたを確認することができます

url.git://.insteadof=https:// 

git config --list 

あなたは出力に次の行が表示されます.gitconfigファイルを使用して、設定ファイルにこのエントリがないことを確認してください。

[url "git://"] 
    insteadOf = https:// 

+1

ああ私の神、この華麗な答えは解決策です。 'ubuntu @ box304:〜$ git config --list'を実行すると' [email protected]:.insteadof = https:// github.com/' - この設定を削除するには'>〜/ .gitconfig'を実行しますあなたの 'circle.yml'ファイルの' machine'セクションでCircleCIの設定を上書きします)。 – RAnders00

+0

喜んで:-) – CodeWizard

関連する問題