Skip to content

Commit

Permalink
[FIXED JENKINS-15416] Filter out non head changes if we're on head
Browse files Browse the repository at this point in the history
  • Loading branch information
mc1arke committed Oct 13, 2012
1 parent c5e2441 commit 1f88112
Show file tree
Hide file tree
Showing 3 changed files with 906 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/main/java/hudson/scm/CvsLog.java
Expand Up @@ -391,6 +391,10 @@ private void saveChange(final CVSChangeLogSet.File file, final CVSChangeLog chan
return;
}

if (branch != null && location instanceof CvsRepositoryLocation.HeadRepositoryLocation) {
return;
}

// Check the branch/tag name matches the retrieved branch name
if (!(location instanceof CvsRepositoryLocation.HeadRepositoryLocation)
&& !location.getLocationName().equals(branch)) {
Expand Down
28 changes: 20 additions & 8 deletions src/test/java/hudson/scm/CvsChangeLogHelperTest.java
Expand Up @@ -6,6 +6,7 @@

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
Expand Down Expand Up @@ -55,10 +56,7 @@ public void testMapCvsLog() throws IOException {
}

public void testMapNonFilteredCvsLog() throws IOException, URISyntaxException {
File changeLogFile = new File(CvsChangeLogHelperTest.class.getResource("cvsRlogOutput_ISSUE-13227.txt").toURI());
int len = (int)changeLogFile.length();
InputStream in = new FileInputStream(changeLogFile); byte[] b = new byte[len]; int total = 0; while (total < len) { int result = in.read(b, total, len - total); if (result == -1) { break; } total += result; }
String logContents = new String(b, Charset.forName("UTF-8"));
String logContents = getFileContents("cvsRlogOutput_ISSUE-13227.txt");

CvsModule module = new CvsModule("portalInt", null);
CvsRepositoryItem item = new CvsRepositoryItem(new CvsRepositoryLocation.BranchRepositoryLocation("d-chg00017366_op_brc_prod-op-2012-04-19", false), new CvsModule[]{module});
Expand All @@ -68,10 +66,7 @@ public void testMapNonFilteredCvsLog() throws IOException, URISyntaxException {
}

public void testMapNonFilteredCvsLog2() throws IOException, URISyntaxException {
File changeLogFile = new File(CvsChangeLogHelperTest.class.getResource("cvsRlogOutput2.txt").toURI());
int len = (int)changeLogFile.length();
InputStream in = new FileInputStream(changeLogFile); byte[] b = new byte[len]; int total = 0; while (total < len) { int result = in.read(b, total, len - total); if (result == -1) { break; } total += result; }
String logContents = new String(b, Charset.forName("UTF-8"));
String logContents = getFileContents("cvsRlogOutput2.txt");

CvsModule module = new CvsModule("branch2", null);
CvsRepositoryItem item = new CvsRepositoryItem(new CvsRepositoryLocation.BranchRepositoryLocation(/*"d-chg00017366_op_brc_prod-op-2012-04-19"*/ "branch2", false), new CvsModule[]{module});
Expand All @@ -80,6 +75,23 @@ public void testMapNonFilteredCvsLog2() throws IOException, URISyntaxException {
assertEquals(3, set.getChanges().size());
}

public void testMapNonFilteredLogHead() throws IOException, URISyntaxException {
String logContents = getFileContents("cvsRlogOutputHead.txt");

CvsModule module = new CvsModule("product", null);
CvsRepositoryItem item = new CvsRepositoryItem(new CvsRepositoryLocation.HeadRepositoryLocation(), new CvsModule[]{module});
CvsRepository repository = new CvsRepository(":pserver:host:/srv/cvs/repositories/iqdoq", false, null, Arrays.asList(new CvsRepositoryItem[]{item}), new ArrayList<ExcludedRegion>(), -1);
assertTrue(new StringCvsLog(logContents).mapCvsLog(repository.getCvsRoot(), item.getLocation()).getChanges().isEmpty());
}


private String getFileContents(String fileName) throws IOException, URISyntaxException {
File changeLogFile = new File(CvsChangeLogHelperTest.class.getResource(fileName).toURI());
int len = (int)changeLogFile.length();
InputStream in = new FileInputStream(changeLogFile); byte[] b = new byte[len]; int total = 0; while (total < len) { int result = in.read(b, total, len - total); if (result == -1) { break; } total += result; }
return new String(b, Charset.forName("UTF-8"));
}

public static class StringCvsLog extends CvsLog {
private final String text;

Expand Down

0 comments on commit 1f88112

Please sign in to comment.