Browse Source

TestRepository: Support committing to unborn symref

Change-Id: I6bcee635adda7c929f6fa68ef20438fe77e49184
stable-4.0
Dave Borowitz 10 years ago
parent
commit
0b625445ef
  1. 3
      org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
  2. 10
      org.eclipse.jgit.test/tst/org/eclipse/jgit/junit/TestRepositoryTest.java

3
org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java

@ -887,10 +887,9 @@ public class TestRepository<R extends Repository> {
branch = b; branch = b;
Ref ref = db.getRef(branch.ref); Ref ref = db.getRef(branch.ref);
if (ref != null) { if (ref != null && ref.getObjectId() != null)
parent(pool.parseCommit(ref.getObjectId())); parent(pool.parseCommit(ref.getObjectId()));
} }
}
CommitBuilder(CommitBuilder prior) throws Exception { CommitBuilder(CommitBuilder prior) throws Exception {
branch = prior.branch; branch = prior.branch;

10
org.eclipse.jgit.test/tst/org/eclipse/jgit/junit/TestRepositoryTest.java

@ -265,6 +265,16 @@ public class TestRepositoryTest {
assertEquals("bar contents", blobAsString(amended, "bar")); 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) private String blobAsString(AnyObjectId treeish, String path)
throws Exception { throws Exception {
RevObject obj = tr.get(rw.parseTree(treeish), path); RevObject obj = tr.get(rw.parseTree(treeish), path);

Loading…
Cancel
Save