Skip to content

Commit

Permalink
[JENKINS-48061] Do something when it's a plain ref
Browse files Browse the repository at this point in the history
  • Loading branch information
rsandell committed Mar 23, 2018
1 parent 5411589 commit ac97524
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/main/java/jenkins/plugins/git/AbstractGitSCMSource.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -360,16 +360,19 @@ private <T, C extends GitSCMSourceContext<C, R>, R extends GitSCMSourceRequest>
*/ */
@CheckForNull @CheckForNull
@Override @Override
protected SCMRevision retrieve(@NonNull final SCMHead head, @NonNull TaskListener listener) protected SCMRevision retrieve(@NonNull final SCMHead head, @NonNull final TaskListener listener)
throws IOException, InterruptedException { throws IOException, InterruptedException {
final GitSCMSourceContext context = new GitSCMSourceContext<>(null, SCMHeadObserver.none()).withTraits(getTraits()); GitSCMSourceContext context = new GitSCMSourceContext<>(null, SCMHeadObserver.none()).withTraits(getTraits());
GitSCMTelescope telescope = GitSCMTelescope.of(this); GitSCMTelescope telescope = GitSCMTelescope.of(this);
if (telescope != null) { if (telescope != null) {
String remote = getRemote(); String remote = getRemote();
StandardUsernameCredentials credentials = getCredentials(); StandardUsernameCredentials credentials = getCredentials();
telescope.validate(remote, credentials); telescope.validate(remote, credentials);
return telescope.getRevision(remote, credentials, head); return telescope.getRevision(remote, credentials, head);
} }
if (head instanceof GitSCMHeadMixin) {
context = context.withoutRefSpecs().withRefSpec(((GitSCMHeadMixin) head).getRef());
}
return doRetrieve(new Retriever<SCMRevision>() { return doRetrieve(new Retriever<SCMRevision>() {
@Override @Override
public SCMRevision run(GitClient client, String remoteName) throws IOException, InterruptedException { public SCMRevision run(GitClient client, String remoteName) throws IOException, InterruptedException {
Expand All @@ -388,7 +391,16 @@ public SCMRevision run(GitClient client, String remoteName) throws IOException,
return new GitBranchSCMRevision((GitBranchSCMHead)head, b.getSHA1String()); return new GitBranchSCMRevision((GitBranchSCMHead)head, b.getSHA1String());
} }
} }
} else { //TODO change to something } else if (head instanceof GitRefSCMHead) {
try {
ObjectId objectId = client.revParse(((GitRefSCMHead) head).getRef());
return new GitRefSCMRevision((GitRefSCMHead)head, objectId.name());
} catch (GitException e) {
// ref could not be found
return null;
}
} else {
listener.getLogger().println("Entering default git retrieve code path");
for (Branch b : client.getRemoteBranches()) { for (Branch b : client.getRemoteBranches()) {
String branchName = StringUtils.removeStart(b.getName(), remoteName + "/"); String branchName = StringUtils.removeStart(b.getName(), remoteName + "/");
if (branchName.equals(head.getName())) { if (branchName.equals(head.getName())) {
Expand Down

0 comments on commit ac97524

Please sign in to comment.