Skip to content
Permalink
Browse files

[JENKINS-48061] retrieveRevisions

  • Loading branch information...
rsandell committed Apr 17, 2018
1 parent f67a66e commit 887ac3394c48e844147de591277a0457adb345a3
@@ -1027,12 +1027,14 @@ public SCMRevision run(GitClient client, String remoteName) throws IOException,
GitClient client = git.getClient();
client.addDefaultCredentials(getCredentials());
Set<String> revisions = new HashSet<>();
if (context.wantBranches() || context.wantTags()) {
if (context.wantBranches() || context.wantTags() || context.wantOtherRefs()) {
listener.getLogger().println("Listing remote references...");
boolean headsOnly = !context.wantOtherRefs() && context.wantBranches();
boolean tagsOnly = !context.wantOtherRefs() && context.wantTags();
Map<String, ObjectId> remoteReferences = client.getRemoteReferences(
getRemote(), null, context.wantBranches(), context.wantTags()
getRemote(), null, headsOnly, tagsOnly
);
for (String name : remoteReferences.keySet()) { //TODO DiscoverOtherRefsTrait
for (String name : remoteReferences.keySet()) {
if (context.wantBranches()) {
if (name.startsWith(Constants.R_HEADS)) {
revisions.add(StringUtils.removeStart(name, Constants.R_HEADS));
@@ -1043,6 +1045,17 @@ public SCMRevision run(GitClient client, String remoteName) throws IOException,
revisions.add(StringUtils.removeStart(name, Constants.R_TAGS));
}
}
if (context.wantOtherRefs() && (!name.startsWith(Constants.R_HEADS) || !name.startsWith(Constants.R_TAGS))) {
for (GitSCMSourceContext.WantedOtherRef o : (Collection<GitSCMSourceContext.WantedOtherRef>)context.getOtherWantedRefs()) {
if (o.matches(name)) {
final String revName = o.getName(name);
if (revName != null) {
revisions.add(revName);
break;
}
}
}
}
}
}
return revisions;
@@ -665,6 +665,41 @@ public boolean isHead(@NonNull Probe probe, @NonNull TaskListener listener) thro
)));
}

@Issue("JENKINS-48061")
@Test
public void fetchOtherRevisions() throws Exception {
sampleRepo.init();
sampleRepo.write("file", "v1");
sampleRepo.git("commit", "--all", "--message=v1");
sampleRepo.git("tag", "v1");
String v1 = sampleRepo.head();
sampleRepo.write("file", "v2");
sampleRepo.git("commit", "--all", "--message=v2"); // master
sampleRepo.git("checkout", "-b", "dev");
sampleRepo.write("file", "v3");
sampleRepo.git("commit", "--all", "--message=v3"); // dev
String v3 = sampleRepo.head();
sampleRepo.git("update-ref", "refs/custom/1", v3);
sampleRepo.git("reset", "--hard", "HEAD^"); // dev
sampleRepo.write("file", "v4");
sampleRepo.git("commit", "--all", "--message=v4"); // dev
// SCM.checkout does not permit a null build argument, unfortunately.
Run<?,?> run = r.buildAndAssertSuccess(r.createFreeStyleProject());
GitSCMSource source = new GitSCMSource(sampleRepo.toString());
source.setTraits(Arrays.asList(new BranchDiscoveryTrait(), new TagDiscoveryTrait(), new DiscoverOtherRefsTrait("custom/*")));
StreamTaskListener listener = StreamTaskListener.fromStderr();

final Set<String> revisions = source.fetchRevisions(listener);

assertThat(revisions, hasSize(4));
assertThat(revisions, containsInAnyOrder(
equalTo("custom-1"),
equalTo("v1"),
equalTo("dev"),
equalTo("master")
));
}

@Issue("JENKINS-37727")
@Test
public void pruneRemovesDeletedBranches() throws Exception {

0 comments on commit 887ac33

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