// reason to poll for a commit
if (!isPollCall && singleBranch.matches("[0-9a-f]{6,40}")) {
try {
ObjectId sha1 = git.revParse(singleBranch);
Revision revision = new Revision(sha1);
revision.getBranches().add(new Branch("detached", sha1));
verbose(listener, "Will build the detached SHA1 {0}", sha1);
return Collections.singletonList(revision);
} catch (GitException e) {
// revision does not exist, may still be a branch
// for example a branch called "badface" would show up here
verbose(listener, "Not a valid SHA1 {0}", singleBranch);
}
}
// if it doesn't contain '/' then it could be either a tag or an unqualified branch
if (!singleBranch.contains("/")) {
// the 'branch' could actually be a tag:
Set<String> tags = git.getTagNames(singleBranch);
if (tags.size() == 0) {
// its not a tag, so lets fully qualify the branch
String repository = gitSCM.getRepositories().get(0).getName();
singleBranch = repository + "/" + singleBranch;
verbose(listener, "{0} is not a tag. Qualifying with the repository {1} a a branch", singleBranch,
repository);
}
}
try {
ObjectId sha1 = git.revParse(singleBranch);
verbose(listener, "rev-parse {0} -> {1}", singleBranch, sha1);
// if polling for changes don't select something that has
// already been built as a build candidate
if (isPollCall && data.hasBeenBuilt(sha1)) {
verbose(listener, "{0} has already been built", sha1);
return emptyList();
}
verbose(listener, "Found a new commit {0} to be built on {1}", sha1, singleBranch);
Revision revision = new Revision(sha1);
revision.getBranches().add(new Branch(singleBranch, sha1));
return Collections.singletonList(revision);
} catch (GitException e) {
// branch does not exist, there is nothing to build
verbose(listener, "Failed to rev-parse: {0}", singleBranch);
return emptyList();