]> source.dussan.org Git - jgit.git/commitdiff
Fix API ListBranchCommand for listmode 'all' 40/2240/1
authorRoberto Tyley <roberto.tyley@guardian.co.uk>
Wed, 12 Jan 2011 14:34:10 +0000 (14:34 +0000)
committerRoberto Tyley <roberto.tyley@guardian.co.uk>
Wed, 12 Jan 2011 14:34:10 +0000 (14:34 +0000)
If remote branches are present they can not be added
to the RefMap from the local branches - the two RefMaps
have a different value of 'prefix' and consequently an
IllegalArgumentException is thrown.

org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java
org.eclipse.jgit/src/org/eclipse/jgit/api/ListBranchCommand.java

index eb1b72ed9c3f25ae8fb230bc844a4b44035420f6..7464a5ea3bb7395b33479fb96ea09e3f2a0cd51a 100644 (file)
@@ -189,6 +189,12 @@ public class BranchCommandTest extends RepositoryTestCase {
                                - allBefore);
        }
 
+       @Test
+       public void testListAllBranchesShouldNotDie() throws Exception {
+               Git git = setUpRepoWithRemote();
+               git.branchList().setListMode(ListMode.ALL).call();
+       }
+
        @Test
        public void testCreateFromCommit() throws Exception {
                Ref branch = git.branchCreate().setName("FromInitial").setStartPoint(
index 8329fca569c099e25199d091d455e74104928a8a..846c5385c566f9b9c8835fc69b353613c9159efd 100644 (file)
@@ -49,6 +49,7 @@ import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
+import java.util.HashMap;
 
 import org.eclipse.jgit.api.errors.JGitInternalException;
 import org.eclipse.jgit.lib.Constants;
@@ -100,7 +101,8 @@ public class ListBranchCommand extends GitCommand<List<Ref>> {
                        } else if (listMode == ListMode.REMOTE) {
                                refList = repo.getRefDatabase().getRefs(Constants.R_REMOTES);
                        } else {
-                               refList = repo.getRefDatabase().getRefs(Constants.R_HEADS);
+                               refList = new HashMap<String,Ref>(repo.getRefDatabase().getRefs(
+                                               Constants.R_HEADS));
                                refList.putAll(repo.getRefDatabase().getRefs(
                                                Constants.R_REMOTES));
                        }