]> source.dussan.org Git - jgit.git/commitdiff
TestRepository: Support committing to unborn symref 42/43742/2
authorDave Borowitz <dborowitz@google.com>
Thu, 12 Mar 2015 17:59:02 +0000 (10:59 -0700)
committerDave Borowitz <dborowitz@google.com>
Thu, 12 Mar 2015 19:46:26 +0000 (12:46 -0700)
Change-Id: I6bcee635adda7c929f6fa68ef20438fe77e49184

org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/junit/TestRepositoryTest.java

index a299d144d4c681d95ee47eeff68fe96eedfb93a1..371e139a889ad733d9fc7df279a8ec3817ecba1a 100644 (file)
@@ -887,9 +887,8 @@ public class TestRepository<R extends Repository> {
                        branch = b;
 
                        Ref ref = db.getRef(branch.ref);
-                       if (ref != null) {
+                       if (ref != null && ref.getObjectId() != null)
                                parent(pool.parseCommit(ref.getObjectId()));
-                       }
                }
 
                CommitBuilder(CommitBuilder prior) throws Exception {
index cc8ed504d00312ff8d5531a9279881b1a9b81376..87ce0117637f11eda8cd5d2e39935a097af7dc52 100644 (file)
@@ -265,6 +265,16 @@ public class TestRepositoryTest {
                assertEquals("bar contents", blobAsString(amended, "bar"));
        }
 
+       @Test
+       public void commitToUnbornHead() throws Exception {
+               repo.updateRef("HEAD").link("refs/heads/master");
+               RevCommit root = tr.branch("HEAD").commit().create();
+               Ref ref = repo.getRef(Constants.HEAD);
+               assertEquals(root, ref.getObjectId());
+               assertTrue(ref.isSymbolic());
+               assertEquals("refs/heads/master", ref.getTarget().getName());
+       }
+
        private String blobAsString(AnyObjectId treeish, String path)
                        throws Exception {
                RevObject obj = tr.get(rw.parseTree(treeish), path);