Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-43507] Fix invalid implicit assumption that remote name is a…
…lways `origin`
  • Loading branch information
stephenc committed Jun 12, 2017
1 parent 55e9a98 commit 7fd9e9f
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/main/java/jenkins/plugins/git/AbstractGitSCMSource.java
Expand Up @@ -516,16 +516,19 @@ public void record(@NonNull SCMHead head, SCMRevision revision, boolean isMatch)
@CheckForNull
@Override
protected SCMRevision retrieve(@NonNull final String revision, @NonNull final TaskListener listener) throws IOException, InterruptedException {

final GitSCMSourceContext context =
new GitSCMSourceContext<>(null, SCMHeadObserver.none()).withTraits(getTraits());
return doRetrieve(new Retriever<SCMRevision>() {
@Override
public SCMRevision run(GitClient client, String remoteName) throws IOException, InterruptedException {
String hash;
try {
hash = client.revParse(revision).name();
} catch (GitException x) {
// Try prepending origin/ in case it was a branch.
// Try prepending remote name in case it was a branch.
try {
hash = client.revParse("origin/" + revision).name();
hash = client.revParse(context.remoteName() + "/" + revision).name();
} catch (GitException x2) {
listener.getLogger().println(x.getMessage());
listener.getLogger().println(x2.getMessage());
Expand All @@ -535,7 +538,7 @@ public SCMRevision run(GitClient client, String remoteName) throws IOException,
return new SCMRevisionImpl(new SCMHead(revision), hash);
}
},
new GitSCMSourceContext<>(null, SCMHeadObserver.none()).withTraits(getTraits()),
context,
listener, false);
}

Expand All @@ -545,18 +548,24 @@ public SCMRevision run(GitClient client, String remoteName) throws IOException,
@NonNull
@Override
protected Set<String> retrieveRevisions(@NonNull final TaskListener listener) throws IOException, InterruptedException {

final GitSCMSourceContext context =
new GitSCMSourceContext<>(null, SCMHeadObserver.none()).withTraits(getTraits());
return doRetrieve(new Retriever<Set<String>>() {
@Override
public Set<String> run(GitClient client, String remoteName) throws IOException, InterruptedException {
Set<String> revisions = new HashSet<String>();
for (Branch branch : client.getRemoteBranches()) {
revisions.add(branch.getName().replaceFirst("^origin/", ""));
revisions.add(branch.getName().replaceFirst(
"^" + Pattern.quote(context.remoteName()) + "/",
""
));
}
revisions.addAll(client.getTagNames("*"));
return revisions;
}
},
new GitSCMSourceContext<>(null, SCMHeadObserver.none()).withTraits(getTraits()),
context,
listener, false);
}

Expand Down

0 comments on commit 7fd9e9f

Please sign in to comment.