Skip to content

Commit

Permalink
DefaultBuildChooser.getCandidateRevisions() now returns Set<Revision>…
Browse files Browse the repository at this point in the history
… to filter duplicates.

[FIXED JENKINS-25639]
  • Loading branch information
wannessels authored and MarkEWaite committed Nov 26, 2014
1 parent ed6e10a commit c0a95d9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Expand Up @@ -69,7 +69,7 @@ public Collection<Revision> getCandidateRevisions(boolean isPollCall, String bra
}
}

Collection<Revision> revisions = new ArrayList<Revision>();
Collection<Revision> revisions = new HashSet<Revision>();

This comment has been minimized.

Copy link
@KostyaSha

KostyaSha Sep 16, 2015

Member

Is it guaranteed that two different branches with the same sha1 will be placed in one Revision object?
Either one of branches will be lost, because Revision uses only sha1 for hash.


// if it doesn't contain '/' then it could be an unqualified branch
if (!branchSpec.contains("/")) {
Expand Down
31 changes: 31 additions & 0 deletions src/test/java/hudson/plugins/git/GitSCMTest.java
Expand Up @@ -23,6 +23,7 @@
import hudson.plugins.git.util.BuildChooserContext;
import hudson.plugins.git.util.BuildChooserContext.ContextCallable;
import hudson.plugins.git.util.BuildData;
import hudson.plugins.git.util.DefaultBuildChooser;
import hudson.plugins.git.util.GitUtils;
import hudson.plugins.parameterizedtrigger.BuildTrigger;
import hudson.plugins.parameterizedtrigger.ResultCondition;
Expand Down Expand Up @@ -62,6 +63,7 @@
import java.net.URI;
import java.net.URL;
import java.util.*;
import org.eclipse.jgit.transport.RemoteConfig;

/**
* Tests for {@link GitSCM}.
Expand Down Expand Up @@ -866,6 +868,35 @@ public void testFetchFromMultipleRepositories() throws Exception {
assertFalse("scm polling should not detect any more changes after build", project.poll(listener).hasChanges());
}

@Bug(25639)
public void testCommitDetectedOnlyOnceInMultipleRepositories() throws Exception {
FreeStyleProject project = setupSimpleProject("master");

TestGitRepo secondTestRepo = new TestGitRepo("secondRepo", this, listener);
List<UserRemoteConfig> remotes = new ArrayList<UserRemoteConfig>();
remotes.addAll(testRepo.remoteConfigs());
remotes.addAll(secondTestRepo.remoteConfigs());

GitSCM gitSCM = new GitSCM(
remotes,
Collections.singletonList(new BranchSpec("origin/master")),
false, Collections.<SubmoduleConfig>emptyList(),
null, null,
Collections.<GitSCMExtension>emptyList());
project.setScm(gitSCM);

commit("commitFile1", johnDoe, "Commit number 1");
FreeStyleBuild build = build(project, Result.SUCCESS, "commitFile1");

commit("commitFile2", johnDoe, "Commit number 2");
git = Git.with(listener, new EnvVars()).in(build.getWorkspace()).getClient();
for (RemoteConfig remoteConfig : gitSCM.getRepositories()) {
git.fetch_().from(remoteConfig.getURIs().get(0), remoteConfig.getFetchRefSpecs());
}
Collection<Revision> candidateRevisions = ((DefaultBuildChooser) (gitSCM).getBuildChooser()).getCandidateRevisions(false, "origin/master", git, listener, project.getLastBuild().getAction(BuildData.class), null);
assertEquals(1, candidateRevisions.size());
}

public void testMerge() throws Exception {
FreeStyleProject project = setupSimpleProject("master");

Expand Down

0 comments on commit c0a95d9

Please sign in to comment.