Skip to content
Permalink
Browse files

[JENKINS-43507] Fix invalid implicit assumption that remote name is a…

…lways `origin`
  • Loading branch information...
stephenc committed May 3, 2017
1 parent 55e9a98 commit 7fd9e9f7826be725a6931d19b6b7ea565181e23a
Showing with 14 additions and 5 deletions.
  1. +14 −5 src/main/java/jenkins/plugins/git/AbstractGitSCMSource.java
@@ -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());
@@ -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);
}
@@ -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);
}

0 comments on commit 7fd9e9f

Please sign in to comment.
You can’t perform that action at this time.