Skip to content

Commit

Permalink
[JENKINS-14026] DefaultBuildChooser should handle smartly branches wi…
Browse files Browse the repository at this point in the history
…th /

When encountering a single branch containing a '/', it is either a qualified branch or a branch containing a '/'
In the first case, the branch should start with the name of a declared remote
Otherwise, we fall back to unqualified behaviour, and we try to match the branch name as if it was */BRANCH
  • Loading branch information
Vlatombe committed Jan 27, 2014
1 parent dcae493 commit ea5cad7
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/main/java/hudson/plugins/git/util/DefaultBuildChooser.java
Expand Up @@ -87,9 +87,27 @@ public Collection<Revision> getCandidateRevisions(boolean isPollCall, String sin
revisions.addAll(getHeadRevision(isPollCall, fqbn, git, listener, data));
}
} else {
// singleBranch contains a '/', so is in most case a fully qualified branch
// doesn't seem we can distinguish unqualified branch with '/' in name, so expect users to fully qualify
revisions.addAll(getHeadRevision(isPollCall, singleBranch, git, listener, data));
// either the branch is qualified (first part should match a valid remote)
// or it is still unqualified, but the branch name contains a '/'
List<String> possibleQualifiedBranches = new ArrayList<String>();
boolean singleBranchIsQualified = false;
for (RemoteConfig config : gitSCM.getRepositories()) {
String repository = config.getName();
if (singleBranch.startsWith(repository + "/")) {
singleBranchIsQualified = true;
break;
}
String fqbn = repository + "/" + singleBranch;
verbose(listener, "Qualifying {0} as a branch in repository {1} -> {2}", singleBranch, repository, fqbn);
possibleQualifiedBranches.add(fqbn);
}
if (singleBranchIsQualified) {
revisions.addAll(getHeadRevision(isPollCall, singleBranch, git, listener, data));
} else {
for (String fqbn : possibleQualifiedBranches) {
revisions.addAll(getHeadRevision(isPollCall, fqbn, git, listener, data));
}
}
}

return revisions;
Expand Down

0 comments on commit ea5cad7

Please sign in to comment.