Skip to content

Commit

Permalink
Merge pull request #15 from JWGmeligMeyling/branch-option
Browse files Browse the repository at this point in the history
Optional branch name
  • Loading branch information
michaeldejong committed Apr 20, 2015
2 parents 188ad24 + 8bf7dd8 commit db87e2b
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,23 @@ private Git cloneRepository(GitSource source, Logger logger, File stagingDirecto
private void checkoutCommit(GitSource source, Logger logger, Git git) throws IOException {
try {
log.info("Checking out revision: {}", source.getCommitId());
CheckoutCommand checkout = git.checkout();
checkout.setStartPoint(source.getCommitId());
checkout.setName(source.getBranchName());
checkout.call();

String branchName = source.getBranchName();

// Checkout commit if no branch specified
// http://stackoverflow.com/a/24893404/2104280
if(branchName == null) {
git.checkout()
.setName(source.getCommitId())
.call();
}
else {
git.checkout()
.setName(source.getBranchName())
.setStartPoint(source.getCommitId())
.setForce(true)
.call();
}
}
catch (GitAPIException e) {
logger.onNextLine("[FATAL] Failed to checkout to specified commit: " + source.getCommitId());
Expand Down

0 comments on commit db87e2b

Please sign in to comment.