Skip to content

Commit

Permalink
Merge pull request #286 from MarkEWaite/getRemoteReferences-enpty-ret…
Browse files Browse the repository at this point in the history
…urn-exception

[JENKINS-30589] Get remote references consistent return in all implementations
  • Loading branch information
MarkEWaite committed Nov 17, 2017
2 parents 1800763 + 1e1f8ff commit c2b1ff4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Expand Up @@ -2807,7 +2807,9 @@ public Map<String, ObjectId> getRemoteReferences(String url, String pattern, boo
Map<String, ObjectId> references = new HashMap<>();
String[] lines = result.split("\n");
for (String line : lines) {
if (line.length() < 41) throw new GitException("unexpected ls-remote output " + line);
if (line.length() < 41) {
continue; // throw new GitException("unexpected ls-remote output " + line);
}
String refName = line.substring(41);
ObjectId refObjectId = ObjectId.fromString(line.substring(0, 40));
if (refName.startsWith("refs/tags") && refName.endsWith("^{}")) {
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/org/jenkinsci/plugins/gitclient/GitClientTest.java
Expand Up @@ -19,6 +19,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
Expand Down Expand Up @@ -866,6 +867,27 @@ public void testGetRemoteReferences() throws Exception {
assertEquals(expResult, result);
}

@Issue("JENKINS-30589")
@Test
public void testGetRemoteReferences_ReturnsEmptyMapIfNoTags() throws Exception {
String url = repoRoot.getAbsolutePath();
String pattern = "**";
boolean headsOnly = false;
boolean tagsOnly = true;
Map<String, ObjectId> result = gitClient.getRemoteReferences(url, pattern, headsOnly, tagsOnly);
assertThat(result, is(Collections.EMPTY_MAP));
}

@Test
public void testGetRemoteReferencesNonExistingPattern() throws Exception {
String url = repoRoot.getAbsolutePath();
String pattern = "non-existent-name";
boolean headsOnly = false;
boolean tagsOnly = false;
Map<String, ObjectId> result = gitClient.getRemoteReferences(url, pattern, headsOnly, tagsOnly);
assertThat(result, is(Collections.EMPTY_MAP));
}

@Test
public void testRevParse() throws Exception {
ObjectId commitA = commitOneFile();
Expand Down

0 comments on commit c2b1ff4

Please sign in to comment.