Skip to content

Commit 92d322c

Browse files
authored
Merge pull request #140 from common-workflow-language/hotfix-git-checkout
Fix for checkouts leaving repository in MERGING state
2 parents cf0e345 + 0d7e968 commit 92d322c

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

src/main/java/org/commonwl/view/git/GitService.java

+4-13
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.eclipse.jgit.api.errors.GitAPIException;
2626
import org.eclipse.jgit.lib.ObjectId;
2727
import org.eclipse.jgit.lib.PersonIdent;
28-
import org.eclipse.jgit.lib.Ref;
2928
import org.eclipse.jgit.revwalk.RevCommit;
3029
import org.slf4j.Logger;
3130
import org.slf4j.LoggerFactory;
@@ -109,21 +108,13 @@ public Git getRepository(GitDetails gitDetails, boolean reuseDir)
109108
// Checkout the specific branch or commit ID
110109
if (repo != null) {
111110
// Create a new local branch if it does not exist and not a commit ID
112-
boolean createBranch = !ObjectId.isId(gitDetails.getBranch());
113-
if (createBranch) {
114-
Ref ref = repo.getRepository().exactRef("refs/heads/" + gitDetails.getBranch());
115-
if (ref != null) {
116-
createBranch = false;
117-
}
111+
String branchOrCommitId = gitDetails.getBranch();
112+
if (!ObjectId.isId(branchOrCommitId)) {
113+
branchOrCommitId = "refs/remotes/origin/" + branchOrCommitId;
118114
}
119115
repo.checkout()
120-
.setCreateBranch(createBranch)
121-
.setName(gitDetails.getBranch())
116+
.setName(branchOrCommitId)
122117
.call();
123-
String branch = repo.getRepository().getFullBranch();
124-
if (branch != null && !branch.startsWith(gitDetails.getBranch())) {
125-
repo.pull().call();
126-
}
127118
}
128119
} catch (IOException ex) {
129120
logger.error("Could not open existing Git repository for '"

0 commit comments

Comments
 (0)