diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RefDirectoryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RefDirectoryTest.java index a61580dd1..56e5549b8 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RefDirectoryTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RefDirectoryTest.java @@ -455,6 +455,19 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertEquals(v1_0, a.getObjectId()); } + @Test + public void testGetRefs_LooseSortedCorrectly() throws IOException { + Map refs; + + writeLooseRef("refs/heads/project1/A", A); + writeLooseRef("refs/heads/project1-B", B); + + refs = refdir.getRefs(RefDatabase.ALL); + assertEquals(2, refs.size()); + assertEquals(A, refs.get("refs/heads/project1/A").getObjectId()); + assertEquals(B, refs.get("refs/heads/project1-B").getObjectId()); + } + @Test public void testGetRefs_TagsOnly_AllPacked() throws IOException { Map tags; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/RefDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/RefDirectory.java index bba634a6b..cd199dcf9 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/RefDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/RefDirectory.java @@ -288,6 +288,7 @@ public class RefDirectory extends RefDatabase { RefList loose; if (scan.newLoose != null) { + scan.newLoose.sort(); loose = scan.newLoose.toRefList(); if (looseRefs.compareAndSet(oldLoose, loose)) modCnt.incrementAndGet(); @@ -312,6 +313,7 @@ public class RefDirectory extends RefDatabase { loose = loose.remove(toRemove); } } + symbolic.sort(); return new RefMap(prefix, packed, upcast(loose), symbolic.toRefList()); }