|
22 | 22 | import org.apache.commons.codec.digest.DigestUtils;
|
23 | 23 | import org.commonwl.view.researchobject.HashableAgent;
|
24 | 24 | import org.eclipse.jgit.api.Git;
|
| 25 | +import org.eclipse.jgit.api.ListBranchCommand; |
25 | 26 | import org.eclipse.jgit.api.errors.GitAPIException;
|
| 27 | +import org.eclipse.jgit.lib.ObjectId; |
26 | 28 | import org.eclipse.jgit.lib.PersonIdent;
|
| 29 | +import org.eclipse.jgit.lib.Ref; |
27 | 30 | import org.eclipse.jgit.revwalk.RevCommit;
|
28 | 31 | import org.slf4j.Logger;
|
29 | 32 | import org.slf4j.LoggerFactory;
|
|
37 | 40 | import java.net.URISyntaxException;
|
38 | 41 | import java.nio.file.Path;
|
39 | 42 | import java.util.HashSet;
|
| 43 | +import java.util.List; |
40 | 44 | import java.util.Set;
|
41 | 45 |
|
42 | 46 | import static org.apache.jena.ext.com.google.common.io.Files.createTempDir;
|
@@ -106,7 +110,28 @@ public Git getRepository(GitDetails gitDetails, boolean reuseDir)
|
106 | 110 |
|
107 | 111 | // Checkout the specific branch or commit ID
|
108 | 112 | if (repo != null) {
|
| 113 | + System.out.println("Listing local branches:"); |
| 114 | + List<Ref> call = repo.branchList().call(); |
| 115 | + for (Ref ref : call) { |
| 116 | + System.out.println("Branch: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName()); |
| 117 | + } |
| 118 | + |
| 119 | + System.out.println("Now including remote branches:"); |
| 120 | + call = repo.branchList().setListMode(ListBranchCommand.ListMode.ALL).call(); |
| 121 | + for (Ref ref : call) { |
| 122 | + System.out.println("Branch: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName()); |
| 123 | + } |
| 124 | + |
| 125 | + // Create a new local branch if it does not exist and not a commit ID |
| 126 | + boolean createBranch = !ObjectId.isId(gitDetails.getBranch()); |
| 127 | + if (createBranch) { |
| 128 | + Ref ref = repo.getRepository().exactRef("refs/heads/" + gitDetails.getBranch()); |
| 129 | + if (ref != null) { |
| 130 | + createBranch = false; |
| 131 | + } |
| 132 | + } |
109 | 133 | repo.checkout()
|
| 134 | + .setCreateBranch(createBranch) |
110 | 135 | .setName(gitDetails.getBranch())
|
111 | 136 | .call();
|
112 | 137 | String branch = repo.getRepository().getFullBranch();
|
|
0 commit comments