Skip to content

Commit

Permalink
Merge pull request #84 from Mathiasdm/master
Browse files Browse the repository at this point in the history
MercurialSCM: add support for revsets
  • Loading branch information
jglick committed Oct 11, 2016
2 parents a2cc98c + 09e739d commit ef1b836
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/main/java/hudson/plugins/mercurial/MercurialSCM.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ public enum RevisionType {
@Override public String getDisplayName() {
return "Changeset";
}
},
REVSET() {
@Override public String getDisplayName() {
return "Revset";
}
};
public abstract String getDisplayName();
}
Expand Down Expand Up @@ -666,7 +671,12 @@ private void determineChanges(Run<?, ?> build, Launcher launcher, TaskListener l
ArgumentListBuilder args = hg.seed(false);
args.add("log");
args.add("--template", MercurialChangeSet.CHANGELOG_TEMPLATE);
args.add("--rev", "ancestors('" + revToBuild.replace("'", "\\'") + "') and not ancestors(" + prevTag.getId() + ")");
if(revisionType == RevisionType.REVSET) {
args.add("--rev", "ancestors(" + revToBuild + ") and not ancestors(" + prevTag.getId() + ")");
}
else {
args.add("--rev", "ancestors('" + revToBuild.replace("'", "\\'") + "') and not ancestors(" + prevTag.getId() + ")");
}
args.add("--encoding", "UTF-8");
args.add("--encodingmode", "replace");

Expand Down
33 changes: 33 additions & 0 deletions src/test/java/hudson/plugins/mercurial/SCMTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,39 @@ protected void assertClone(String log, boolean cloneExpected) {
assertTrue(JenkinsRule.getLog(b), ws.child("f3").exists());
}

@Test public void revsets() throws Exception {
m.hg(repo, "init");
m.touchAndCommit(repo, "f1");
m.touchAndCommit(repo, "f2");
m.hg(repo, "log");
FreeStyleProject p = j.createFreeStyleProject();
p.setScm(new MercurialSCM(hgInstallation(), repo.getPath(), MercurialSCM.RevisionType.REVSET, "first(parents(tip))", null, null, null, false, null));
FreeStyleBuild b = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
FilePath ws = b.getWorkspace();
//We expect to be on the parent of f2: only f1 is present
assertTrue(ws.child("f1").exists());
assertFalse(ws.child("f2").exists());

m.hg(repo, "update", "-r", "0");
m.touchAndCommit(repo, "f3");
m.hg(repo, "merge");
m.hg(repo, "commit", "-m", "Merged some stuff");
b = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
ws = b.getWorkspace();
//We expect to be on the first parent of the merge: f3 is not present
assertTrue(ws.child("f1").exists());
assertTrue(ws.child("f2").exists());
assertFalse(ws.child("f3").exists());

m.touchAndCommit(repo, "f4");
b = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
ws = b.getWorkspace();
//We expect to be on the merge itself: f4 is not present
assertTrue(ws.child("f1").exists());
assertTrue(ws.child("f2").exists());
assertTrue(ws.child("f3").exists());
assertFalse(ws.child("f4").exists());
}
private void assertChangeSetPaths(List<? extends Set<String>> expectedChangeSetPaths,
AbstractBuild<?, ?> build) throws IOException {
ChangeLogSet<? extends Entry> actualChangeLogSet = build.getChangeSet();
Expand Down

0 comments on commit ef1b836

Please sign in to comment.