Skip to content

Commit

Permalink
[FIXED JENKINS-13368] Fixed GitAPI so it does both the older style of
Browse files Browse the repository at this point in the history
checking for changed
files, and used the recommended change.  Added test case for commits to
included files that were changed further back than the last commit.
  • Loading branch information
David Tanner committed Oct 26, 2012
1 parent 2bf5f34 commit f160f6f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/main/java/hudson/plugins/git/GitAPI.java
Expand Up @@ -18,6 +18,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.io.StringReader;
import java.io.StringWriter;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
Expand Down Expand Up @@ -388,19 +389,22 @@ private void whatchanged(String revFrom, String revTo, OutputStream outputStream
* @throws GitException if errors were encountered running git show.
*/
public List<String> showRevision(Revision r, BuildData buildData) throws GitException {
String revName = r.getSha1String();
StringWriter writer = new StringWriter();
String revName = "";


if (buildData != null){
revName = buildData.lastBuild.revision.getSha1String() + ".." + r.getSha1String();
writer.write(launchCommand("show", "--no-abbrev", "--format=raw", "-M", "--raw", revName));
writer.write("\\n");
}
String result = "";

revName = r.getSha1String();
writer.write(launchCommand("whatchanged", "--no-abbrev", "-M", "-m", "--pretty=raw", "-1", revName));

if (revName != null) {
if (buildData != null){
result = launchCommand("show", "--no-abbrev", "--format=raw", "-M", "--raw", revName);
} else {
result = launchCommand("whatchanged", "--no-abbrev", "-M", "-m", "--pretty=raw", "-1", revName);
}
}
String result = "";

result = writer.toString();

List<String> revShow = new ArrayList<String>();

Expand Down
36 changes: 36 additions & 0 deletions src/test/java/hudson/plugins/git/GitSCMTest.java
Expand Up @@ -136,6 +136,42 @@ public void testBasicIncludedRegion() throws Exception {
assertBuildStatusSuccess(build2);
assertFalse("scm polling should not detect any more changes after build", project.pollSCMChanges(listener));
}

public void testIncludedRegionWithDeeperCommits() throws Exception {
FreeStyleProject project = setupProject("master", false, null, null, null, ".*3");

// create initial commit and then run the build against it:
final String commitFile1 = "commitFile1";
commit(commitFile1, johnDoe, "Commit number 1");
build(project, Result.SUCCESS, commitFile1);

assertFalse("scm polling should not detect any more changes after build", project.pollSCMChanges(listener));

final String commitFile2 = "commitFile2";
commit(commitFile2, janeDoe, "Commit number 2");
assertFalse("scm polling detected commit2 change, which should not have been included", project.pollSCMChanges(listener));


final String commitFile3 = "commitFile3";
commit(commitFile3, johnDoe, "Commit number 3");

final String commitFile4 = "commitFile4";
commit(commitFile4, janeDoe, "Commit number 4");
assertTrue("scm polling did not detect commit3 change", project.pollSCMChanges(listener));

//... and build it...
final FreeStyleBuild build2 = build(project, Result.SUCCESS, commitFile2, commitFile3);
final Set<User> culprits = build2.getCulprits();
assertEquals("The build should have two culprit", 2, culprits.size());

PersonIdent[] expected = {johnDoe, janeDoe};
assertCulprits("jane doe and john doe should be the culprits", culprits, expected);

assertTrue(build2.getWorkspace().child(commitFile2).exists());
assertTrue(build2.getWorkspace().child(commitFile3).exists());
assertBuildStatusSuccess(build2);
assertFalse("scm polling should not detect any more changes after build", project.pollSCMChanges(listener));
}

public void testBasicExcludedRegion() throws Exception {
FreeStyleProject project = setupProject("master", false, null, ".*2", null, null);
Expand Down

0 comments on commit f160f6f

Please sign in to comment.