|
23 | 23 | import org.commonwl.view.researchobject.HashableAgent;
|
24 | 24 | import org.eclipse.jgit.api.Git;
|
25 | 25 | import org.eclipse.jgit.api.errors.GitAPIException;
|
| 26 | +import org.eclipse.jgit.api.errors.RefNotFoundException; |
26 | 27 | import org.eclipse.jgit.lib.ObjectId;
|
27 | 28 | import org.eclipse.jgit.lib.PersonIdent;
|
28 | 29 | import org.eclipse.jgit.revwalk.RevCommit;
|
@@ -67,7 +68,7 @@ public GitService(@Value("${gitStorage}") Path gitStorage,
|
67 | 68 | * Gets a repository, cloning into a local directory or
|
68 | 69 | * @param gitDetails The details of the Git repository
|
69 | 70 | * @param reuseDir Whether the cached repository can be used
|
70 |
| - * @returns The git object for the repository |
| 71 | + * @return The git object for the repository |
71 | 72 | */
|
72 | 73 | public Git getRepository(GitDetails gitDetails, boolean reuseDir)
|
73 | 74 | throws GitAPIException, IOException {
|
@@ -106,12 +107,33 @@ public Git getRepository(GitDetails gitDetails, boolean reuseDir)
|
106 | 107 | if (repo != null) {
|
107 | 108 | // Create a new local branch if it does not exist and not a commit ID
|
108 | 109 | String branchOrCommitId = gitDetails.getBranch();
|
109 |
| - if (!ObjectId.isId(branchOrCommitId)) { |
| 110 | + final boolean isId = ObjectId.isId(branchOrCommitId); |
| 111 | + if (!isId) { |
110 | 112 | branchOrCommitId = "refs/remotes/origin/" + branchOrCommitId;
|
111 | 113 | }
|
112 |
| - repo.checkout() |
113 |
| - .setName(branchOrCommitId) |
114 |
| - .call(); |
| 114 | + try { |
| 115 | + repo.checkout() |
| 116 | + .setName(branchOrCommitId) |
| 117 | + .call(); |
| 118 | + } |
| 119 | + catch (Exception ex) { |
| 120 | + // Maybe it was a tag |
| 121 | + if (!isId && ex instanceof RefNotFoundException) { |
| 122 | + final String tag = gitDetails.getBranch(); |
| 123 | + try { |
| 124 | + repo.checkout() |
| 125 | + .setName(tag) |
| 126 | + .call(); |
| 127 | + } |
| 128 | + catch (Exception ex2) { |
| 129 | + // Throw the first exception, to keep the same behavior as before. |
| 130 | + throw ex; |
| 131 | + } |
| 132 | + } |
| 133 | + else { |
| 134 | + throw ex; |
| 135 | + } |
| 136 | + } |
115 | 137 | }
|
116 | 138 |
|
117 | 139 | return repo;
|
|
0 commit comments