Browse Source

RefDirectory: Do not use search path to find additional refs

Psuedorefs like FETCH_HEAD and MERGE_HEAD are supposed to be directly
under the .git directory, not in other locations in the SEARCH_PATH
like refs/ and refs/heads/.  Use exactRef to access them.

Change-Id: Iab8ac47008822fa78fc0691e239e518c34d7a98e
Signed-off-by: Jonathan Nieder <jrn@google.com>
stable-5.3
Jonathan Nieder 9 years ago
parent
commit
b2ec6405e4
  1. 23
      org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefDirectoryTest.java
  2. 2
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java

23
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefDirectoryTest.java

@ -48,6 +48,7 @@ import static org.eclipse.jgit.lib.Constants.R_HEADS;
import static org.eclipse.jgit.lib.Constants.R_TAGS;
import static org.eclipse.jgit.lib.Ref.Storage.LOOSE;
import static org.eclipse.jgit.lib.Ref.Storage.NEW;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@ -1098,6 +1099,28 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertNull(refdir.exactRef("v1.0"));
}
@Test
public void testGetAdditionalRefs_OrigHead() throws IOException {
writeLooseRef("ORIG_HEAD", A);
List<Ref> refs = refdir.getAdditionalRefs();
assertEquals(1, refs.size());
Ref r = refs.get(0);
assertFalse(r.isSymbolic());
assertEquals(A, r.getObjectId());
assertEquals("ORIG_HEAD", r.getName());
assertFalse(r.isPeeled());
assertNull(r.getPeeledObjectId());
}
@Test
public void testGetAdditionalRefs_OrigHeadBranch() throws IOException {
writeLooseRef("refs/heads/ORIG_HEAD", A);
List<Ref> refs = refdir.getAdditionalRefs();
assertArrayEquals(new Ref[0], refs.toArray());
}
@Test
public void testGetRef_FetchHead() throws IOException {
// This is an odd special case where we need to make sure we read

2
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java

@ -412,7 +412,7 @@ public class RefDirectory extends RefDatabase {
public List<Ref> getAdditionalRefs() throws IOException {
List<Ref> ret = new LinkedList<>();
for (String name : additionalRefsNames) {
Ref r = getRef(name);
Ref r = exactRef(name);
if (r != null)
ret.add(r);
}

Loading…
Cancel
Save