summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst
diff options
context:
space:
mode:
authorJonathan Nieder <jrn@google.com>2015-11-10 15:11:04 -0800
committerJonathan Nieder <jrn@google.com>2015-11-11 10:56:39 -0800
commit797f94d3319a6bea2cacce707a6a5ee67f00ea17 (patch)
tree8d4a7746dc06ae7f034cb6f38ee49013a74651de /org.eclipse.jgit.test/tst
parentee66914e410a258d8d8acd877a97f9152e2c1a41 (diff)
downloadjgit-797f94d3319a6bea2cacce707a6a5ee67f00ea17.tar.gz
jgit-797f94d3319a6bea2cacce707a6a5ee67f00ea17.zip
RefDirectory.exactRef: Do not ignore symrefs to unborn branch
When asked to read a symref pointing to a branch-yet-to-be-born (such as HEAD in a newly initialized repository), DfsRepository and FileRepository return different results. FileRepository: exactRef("HEAD") => null DfsRepository: exactRef("HEAD") => SymbolicRef[HEAD -> refs/heads/master=00000000] getRef("HEAD") returns the same as DfsRepository's exactRef in both backends. The intended behavior is the DfsRepository one: exactRef() is supposed to be like getRef(), but more exact because it doesn't need to traverse the search path. The discrepancy is because DfsRefDatabase implements exactRef() directly with the intended semantics, while RefDirectory uses a fallback implementation built on top of getRefs(). getRefs() skips symrefs to an unborn branch. Override the fallback implementation with a correct implementation that is similar to getRef() to avoid this. A followup change will fix the fallback. Change-Id: Ic138a5564a099ebf32248d86b93e2de9ab3c94ee Reported-by: David Pursehouse <david.pursehouse@sonymobile.com> Improved-by: Christian Halstrick <christian.halstrick@sap.com> Bug: 478865
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefDirectoryTest.java19
1 files changed, 19 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefDirectoryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefDirectoryTest.java
index 0991598920..d66753da08 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefDirectoryTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefDirectoryTest.java
@@ -1025,6 +1025,25 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
}
@Test
+ public void testExactRef_EmptyDatabase() throws IOException {
+ Ref r;
+
+ r = refdir.exactRef(HEAD);
+ assertTrue(r.isSymbolic());
+ assertSame(LOOSE, r.getStorage());
+ assertEquals("refs/heads/master", r.getTarget().getName());
+ assertSame(NEW, r.getTarget().getStorage());
+ assertNull(r.getTarget().getObjectId());
+
+ assertNull(refdir.exactRef("refs/heads/master"));
+ assertNull(refdir.exactRef("refs/tags/v1.0"));
+ assertNull(refdir.exactRef("FETCH_HEAD"));
+ assertNull(refdir.exactRef("NOT.A.REF.NAME"));
+ assertNull(refdir.exactRef("master"));
+ assertNull(refdir.exactRef("v1.0"));
+ }
+
+ @Test
public void testGetRef_FetchHead() throws IOException {
// This is an odd special case where we need to make sure we read
// exactly the first 40 bytes of the file and nothing further on