Skip to content
Permalink
Browse files

Merge pull request #228 from mlex/master

[JENKINS-20392] Fix "Recent History" for merge jobs.
  • Loading branch information...
MarkEWaite committed Aug 9, 2014
2 parents f397b19 + beab37d commit 7b1f340b37f8425ee3dea3e104727f456d53eb9f
@@ -5,6 +5,7 @@
import hudson.plugins.git.GitException;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.Revision;
import hudson.plugins.git.Branch;
import hudson.plugins.git.UserMergeOptions;
import hudson.plugins.git.extensions.GitClientType;
import hudson.plugins.git.extensions.GitSCMExtension;
@@ -90,7 +91,9 @@ public Revision decorateRevisionToBuild(GitSCM scm, Run<?, ?> build, GitClient g

build.addAction(new MergeRecord(remoteBranchRef,target.getName()));

return new GitUtils(listener,git).getRevisionForSHA1(git.revParse(HEAD));
Revision mergeRevision = new GitUtils(listener,git).getRevisionForSHA1(git.revParse(HEAD));
mergeRevision.getBranches().add(new Branch(remoteBranchRef, target));
return mergeRevision;
}

@Override
@@ -131,6 +131,9 @@ public void saveBuild(Build build) {
for(Branch branch : build.marked.getBranches()) {
buildsByBranchName.put(fixNull(branch.getName()), build);
}
for(Branch branch : build.revision.getBranches()) {
buildsByBranchName.put(fixNull(branch.getName()), build);
}
}

public Build getLastBuildOfBranch(String branch) {
@@ -23,6 +23,7 @@
import hudson.remoting.Callable;
import hudson.remoting.Channel;
import hudson.remoting.VirtualChannel;
import hudson.scm.ChangeLogSet;
import hudson.scm.PollingResult;
import hudson.slaves.DumbSlave;
import hudson.slaves.EnvironmentVariablesNodeProperty.Entry;
@@ -879,6 +880,40 @@ public void testMerge() throws Exception {
assertFalse("scm polling should not detect any more changes after build", project.poll(listener).hasChanges());
}

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

GitSCM scm = new GitSCM(
createRemoteRepositories(),
Collections.singletonList(new BranchSpec("*")),
false, Collections.<SubmoduleConfig>emptyList(),
null, null,
Collections.<GitSCMExtension>emptyList());
scm.getExtensions().add(new PreBuildMerge(new UserMergeOptions("origin", "integration", "default")));
project.setScm(scm);

// create initial commit and then run the build against it:
// Here the changelog is by default empty (because changelog for first commit is always empty
commit("commitFileBase", johnDoe, "Initial Commit");
testRepo.git.branch("integration");
build(project, Result.SUCCESS, "commitFileBase");

// Create second commit and run build
// Here the changelog should contain exactly this one new commit
testRepo.git.checkout("master", "topic2");
final String commitFile2 = "commitFile2";
String commitMessage = "Commit number 2";
commit(commitFile2, johnDoe, commitMessage);
final FreeStyleBuild build2 = build(project, Result.SUCCESS, commitFile2);

ChangeLogSet<? extends ChangeLogSet.Entry> changeLog = build2.getChangeSet();
assertEquals("Changelog should contain one item", 1, changeLog.getItems().length);

GitChangeSet singleChange = (GitChangeSet) changeLog.getItems()[0];
assertEquals("Changelog should contain commit number 2", commitMessage, singleChange.getComment().trim());
}

public void testMergeWithSlave() throws Exception {
FreeStyleProject project = setupSimpleProject("master");
project.setAssignedLabel(createSlave().getSelfLabel());

0 comments on commit 7b1f340

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