Skip to content

Commit

Permalink
JENKINS-26417 Add a unit test for clone with multiple refspecs
Browse files Browse the repository at this point in the history
Rolling back the change to #getBranches()
  • Loading branch information
Vincent LATOMBE authored and MarkEWaite committed Jan 24, 2015
1 parent 1a5f40d commit ada4ade
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Expand Up @@ -469,7 +469,7 @@ else if (!referencePath.isDirectory())
.execute();;
setRemoteUrl(origin, url);
for (RefSpec refSpec : refspecs) {
launchCommand("config", "remote." + origin + ".fetch", refSpec.toString());
launchCommand("config", "--add", "remote." + origin + ".fetch", refSpec.toString());
}
}

Expand Down Expand Up @@ -1579,10 +1579,7 @@ protected Set<Branch> parseBranches(String fos) throws GitException, Interrupted
}

public Set<Branch> getBranches() throws GitException, InterruptedException {
// git branch -a will return remote branches prefixed by remotes/,
// while git branch -r will return them with the correct name
return Sets.union(parseBranches(launchCommand("branch")),
parseBranches(launchCommand("branch", "-r")));
return parseBranches(launchCommand("branch", "-a"));
}

public Set<Branch> getRemoteBranches() throws GitException, InterruptedException {
Expand Down
21 changes: 19 additions & 2 deletions src/test/java/org/jenkinsci/plugins/gitclient/GitAPITestCase.java
Expand Up @@ -564,6 +564,23 @@ public Void invoke(final Repository implRepo, VirtualChannel channel) {
});
}

@NotImplementedInJGit
public void test_clone_refspecs() throws Exception {
List<RefSpec> refspecs = Lists.newArrayList(
new RefSpec("+refs/heads/master:refs/remotes/origin/master"),
new RefSpec("+refs/heads/1.4.x:refs/remotes/origin/1.4.x")
);
w.git.clone_().url(localMirror()).refspecs(refspecs).repositoryName("origin").execute();
w.git.withRepository(new RepositoryCallback<Void>() {
public Void invoke(Repository repo, VirtualChannel channel) throws IOException, InterruptedException {
String[] fetchRefSpecs = repo.getConfig().getStringList(ConfigConstants.CONFIG_REMOTE_SECTION, Constants.DEFAULT_REMOTE_NAME, "fetch");
assertEquals("Expected 2 refspecs", 2, fetchRefSpecs.length);
assertEquals("Incorrect refspec 1", "+refs/heads/master:refs/remotes/origin/master", fetchRefSpecs[0]);
assertEquals("Incorrect refspec 2", "+refs/heads/1.4.x:refs/remotes/origin/1.4.x", fetchRefSpecs[1]);
return null;
}});
}

public void test_detect_commit_in_repo() throws Exception {
w.init();
w.touch("file1");
Expand Down Expand Up @@ -1158,7 +1175,7 @@ public void test_fetch_shallow() throws Exception {
w.git.setRemoteUrl("origin", localMirror());
w.git.fetch_().from(new URIish("origin"), Collections.singletonList(new RefSpec("refs/heads/*:refs/remotes/origin/*"))).shallow(true).execute();
check_remote_url("origin");
assertBranchesExist(w.git.getBranches(), "origin/master");
assertBranchesExist(w.git.getRemoteBranches(), "origin/master");
final String alternates = ".git" + File.separator + "objects" + File.separator + "info" + File.separator + "alternates";
assertFalse("Alternates file found: " + alternates, w.exists(alternates));
final String shallow = ".git" + File.separator + "shallow";
Expand All @@ -1170,7 +1187,7 @@ public void test_fetch_noTags() throws Exception {
w.git.setRemoteUrl("origin", localMirror());
w.git.fetch_().from(new URIish("origin"), Collections.singletonList(new RefSpec("refs/heads/*:refs/remotes/origin/*"))).tags(false).execute();
check_remote_url("origin");
assertBranchesExist(w.git.getBranches(), "origin/master");
assertBranchesExist(w.git.getRemoteBranches(), "origin/master");
Set<String> tags = w.git.getTagNames("");
assertTrue("Tags have been found : " + tags, tags.isEmpty());
}
Expand Down

0 comments on commit ada4ade

Please sign in to comment.