From 944fcdae66bb4de712e2eadec73d8008d3a9bace Mon Sep 17 00:00:00 2001 From: Roberto Tyley Date: Wed, 12 Jan 2011 14:34:10 +0000 Subject: [PATCH] Fix API ListBranchCommand for listmode 'all' 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. --- .../tst/org/eclipse/jgit/api/BranchCommandTest.java | 6 ++++++ .../src/org/eclipse/jgit/api/ListBranchCommand.java | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java index eb1b72ed9..7464a5ea3 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java @@ -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( diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/ListBranchCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/ListBranchCommand.java index 8329fca56..846c5385c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/ListBranchCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/ListBranchCommand.java @@ -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> { } else if (listMode == ListMode.REMOTE) { refList = repo.getRefDatabase().getRefs(Constants.R_REMOTES); } else { - refList = repo.getRefDatabase().getRefs(Constants.R_HEADS); + refList = new HashMap(repo.getRefDatabase().getRefs( + Constants.R_HEADS)); refList.putAll(repo.getRefDatabase().getRefs( Constants.R_REMOTES)); }