Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

Commit

Permalink
Merge pull request #271 from abayer/jenkins-29326
Browse files Browse the repository at this point in the history
[JENKINS-29326] Don't add duplicate BuildData (downstream)
  • Loading branch information
abayer committed Dec 16, 2015
2 parents ae6814b + b5dcfe2 commit 3840d8c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
Expand Up @@ -26,6 +26,8 @@

import hudson.model.Label;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.GitTagAction;
import hudson.plugins.git.util.BuildData;
import hudson.scm.ChangeLogSet;
import hudson.scm.SCM;
import hudson.triggers.SCMTrigger;
Expand All @@ -36,8 +38,11 @@
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import static org.junit.Assert.*;

import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;

public class GitStepTest {
Expand Down Expand Up @@ -162,4 +167,39 @@ public class GitStepTest {
assertFalse(iterator.hasNext());
}

// TODO: Remove this Ignore after git plugin 2.4.1 is released.
@Ignore("This test is currently disabled until the fix for JENKINS-29326 is released in the git plugin 2.4.1 or later.")
@Issue("JENKINS-29326")
@Test
public void identicalGitSCMs() throws Exception {
otherRepo.git("init");
otherRepo.write("firstfile", "");
otherRepo.git("add", "firstfile");
otherRepo.git("commit", "--message=init");
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "demo");
p.setDefinition(new CpsFlowDefinition(
"node {\n" +
" dir('main') {\n" +
" git($/" + otherRepo + "/$)\n" +
" }\n" +
" dir('other') {\n" +
" git($/" + otherRepo + "/$)\n" +
" }\n" +
"}"));
WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
assertEquals(1, b.getActions(BuildData.class).size());
assertEquals(1, b.getActions(GitTagAction.class).size());
assertEquals(0, b.getChangeSets().size());
assertEquals(1, p.getSCMs().size());

otherRepo.write("secondfile", "");
otherRepo.git("add", "secondfile");
otherRepo.git("commit", "--message=second");
WorkflowRun b2 = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
assertEquals(1, b2.getActions(BuildData.class).size());
assertEquals(1, b2.getActions(GitTagAction.class).size());
assertEquals(1, b2.getChangeSets().size());
assertFalse(b2.getChangeSets().get(0).isEmptySet());
assertEquals(1, p.getSCMs().size());
}
}
Expand Up @@ -71,6 +71,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -444,11 +445,11 @@ public void addTrigger(Trigger trigger) {
if (b == null) {
return Collections.emptySet();
}
List<SCM> scms = new LinkedList<SCM>();
Map<String,SCM> scms = new LinkedHashMap<String,SCM>();
for (WorkflowRun.SCMCheckout co : b.checkouts(null)) {
scms.add(co.scm);
scms.put(co.scm.getKey(), co.scm);
}
return scms;
return scms.values();
}

public @CheckForNull SCM getTypicalSCM() {
Expand Down

0 comments on commit 3840d8c

Please sign in to comment.