Skip to content
Permalink
Browse files
[JENKINS-26842] Handle regex branch spec which does not contain '*'
Apply code changes via patch ignoring mismatched whitespace
  • Loading branch information
Joshua Johnston authored and MarkEWaite committed Feb 10, 2015
1 parent 1c397db commit 94dff14649c5989677406ad1a19115560a812dc8
Showing 3 changed files with 37 additions and 1 deletion.
@@ -49,7 +49,7 @@ public Collection<Revision> getCandidateRevisions(boolean isPollCall, String bra

// if the branch name contains more wildcards then the simple usecase
// does not apply and we need to skip to the advanced usecase
if (branchSpec == null || branchSpec.contains("*"))
if (isAdvancedSpec(branchSpec))
return getAdvancedCandidateRevisions(isPollCall,listener,new GitUtils(listener,git),data, context);

// check if we're trying to build a specific commit
@@ -307,4 +307,17 @@ public String getLegacyId() {
return "Default";
}
}

/**
* Helper to determine if the branchSpec requires advanced matching
*
* - if the branch name contains more wildcards then the simple usecase
* - if the branch name should be treated as regexp
* @param branchSpec
* @return
*/
boolean isAdvancedSpec(String branchSpec) {
// null or wildcards or regexp
return (branchSpec == null || branchSpec.contains("*") || branchSpec.startsWith(":"));
}
}
@@ -147,4 +147,13 @@ public void testUsesJavaPatternDirectlyIfPrefixedWithColon() {
assertFalse(m.matches("origin/prefix"));
assertFalse(m.matches("origin/prefix-abc"));
}

public void testUsesJavaPatternWithRepetition() {
// match pattern from JENKINS-26842
BranchSpec m = new BranchSpec(":origin/release-\\d{8}");
assertTrue(m.matches("origin/release-20150101"));
assertFalse(m.matches("origin/release-2015010"));
assertFalse(m.matches("origin/release-201501011"));
assertFalse(m.matches("origin/release-20150101-something"));
}
}
@@ -27,4 +27,18 @@ public void testChooseGitRevisionToBuildByShaHash() throws Exception {
candidateRevisions = buildChooser.getCandidateRevisions(false, "aaa" + shaHashCommit1.substring(3), git, null, null, null);
assertTrue(candidateRevisions.isEmpty());
}
/**
* RegExp patterns prefixed with : should pass through to DefaultBuildChooser.getAdvancedCandidateRevisions
* @throws Exception
*/
public void testIsAdvancedSpec() throws Exception {
DefaultBuildChooser buildChooser = (DefaultBuildChooser) new GitSCM("foo").getBuildChooser();

assertFalse(buildChooser.isAdvancedSpec("origin/master"));
assertTrue(buildChooser.isAdvancedSpec("origin/master-*"));
assertTrue(buildChooser.isAdvancedSpec("origin**"));
// regexp use case
assertTrue(buildChooser.isAdvancedSpec(":origin/master"));
assertTrue(buildChooser.isAdvancedSpec(":origin/master-\\d{*}"));
}
}

0 comments on commit 94dff14

Please sign in to comment.