在 JGit 中获取异常“org.eclipse.jgit.api.errors.InvalidConfigurationException:无密钥远程值”

KOU*_*DAL 3 java git jgit

我正在尝试从托管在 bitbucket 的远程存储库中提取数据。为此,我使用 JGit。我的代码如下;

        Git git = Git.open( new File( localPath+"/.git" ) );

        PullCommand pullCmd = git.pull();
        pullCmd.setCredentialsProvider(this.credentialsProvider);
        pullCmd.setRemoteBranchName(branch);
        //pullCmd.setRemote("origin");
        pullCmd.setRemote(remoteUrl);

        PullResult result = pullCmd.call();
        //FetchResult fetchResult = result.getFetchResult();
        //MergeResult mergeResult = result.getMergeResult();
        //mergeResult.getMergeStatus();
Run Code Online (Sandbox Code Playgroud)

但我总是遇到例外,

    org.eclipse.jgit.api.errors.InvalidConfigurationException: No value for key remote.https://xyz@bitbucket.org/xyz/testproject.git.url found in configuration
        at org.eclipse.jgit.api.PullCommand.call(PullCommand.java:266)
        at git.GitPullOperation.execute(GitPullOperation.java:37)
        at ui.MainScreen.invokeGitOperation(MainScreen.java:214)
Run Code Online (Sandbox Code Playgroud)

尝试了 stackoverflow 中的所有答案,但没有任何效果。

任何帮助对我来说都是很大的。

jsa*_*ryd 5

您看到的错误表明它正在尝试读取不存在的配置密钥。这个特定的键使用远程名称,而不是 URL。

该行似乎pullCmd.setRemote(remoteUrl);需要远程名称而不是 URL。如果您已经克隆了存储库,则origin默认情况下您将拥有一个远程命名的存储库,因此可以:

pullCmd.setRemote(remoteUrl);
Run Code Online (Sandbox Code Playgroud)

尝试将值设置为origin

pullCmd.setRemote("origin");
Run Code Online (Sandbox Code Playgroud)