Skip to content

Commit

Permalink
Merge pull request #140 from common-workflow-language/hotfix-git-chec…
Browse files Browse the repository at this point in the history
…kout

Fix for checkouts leaving repository in MERGING state
  • Loading branch information
stain authored Aug 11, 2017
2 parents cf0e345 + 0d7e968 commit 92d322c
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions src/main/java/org/commonwl/view/git/GitService.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.revwalk.RevCommit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -109,21 +108,13 @@ public Git getRepository(GitDetails gitDetails, boolean reuseDir)
// Checkout the specific branch or commit ID
if (repo != null) {
// Create a new local branch if it does not exist and not a commit ID
boolean createBranch = !ObjectId.isId(gitDetails.getBranch());
if (createBranch) {
Ref ref = repo.getRepository().exactRef("refs/heads/" + gitDetails.getBranch());
if (ref != null) {
createBranch = false;
}
String branchOrCommitId = gitDetails.getBranch();
if (!ObjectId.isId(branchOrCommitId)) {
branchOrCommitId = "refs/remotes/origin/" + branchOrCommitId;
}
repo.checkout()
.setCreateBranch(createBranch)
.setName(gitDetails.getBranch())
.setName(branchOrCommitId)
.call();
String branch = repo.getRepository().getFullBranch();
if (branch != null && !branch.startsWith(gitDetails.getBranch())) {
repo.pull().call();
}
}
} catch (IOException ex) {
logger.error("Could not open existing Git repository for '"
Expand Down

0 comments on commit 92d322c

Please sign in to comment.