summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefUpdateTest.java58
1 files changed, 58 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefUpdateTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefUpdateTest.java
index fa77c6a8d2..d851528cdd 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefUpdateTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefUpdateTest.java
@@ -293,6 +293,64 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
}
/**
+ * Update the HEAD ref. Only it should be changed, not what it points to.
+ *
+ * @throws Exception
+ */
+ public void testUpdateRefDetached() throws Exception {
+ ObjectId pid = db.resolve("refs/heads/master");
+ ObjectId ppid = db.resolve("refs/heads/master^");
+ RefUpdate updateRef = db.updateRef("HEAD", true);
+ updateRef.setForceUpdate(true);
+ updateRef.setNewObjectId(ppid);
+ Result update = updateRef.update();
+ assertEquals(Result.FORCED, update);
+ assertEquals(ppid, db.resolve("HEAD"));
+ Ref ref = db.getRef("HEAD");
+ assertEquals("HEAD", ref.getName());
+ assertEquals("HEAD", ref.getOrigName());
+
+ // the branch HEAD referred to is left untouched
+ assertEquals(pid, db.resolve("refs/heads/master"));
+ ReflogReader reflogReader = new ReflogReader(db, "HEAD");
+ org.eclipse.jgit.lib.ReflogReader.Entry e = reflogReader.getReverseEntries().get(0);
+ assertEquals(pid, e.getOldId());
+ assertEquals(ppid, e.getNewId());
+ assertEquals("GIT_COMMITTER_EMAIL", e.getWho().getEmailAddress());
+ assertEquals("GIT_COMMITTER_NAME", e.getWho().getName());
+ assertEquals(1250379778000L, e.getWho().getWhen().getTime());
+ }
+
+ /**
+ * Update the HEAD ref when the referenced branch is unborn
+ *
+ * @throws Exception
+ */
+ public void testUpdateRefDetachedUnbornHead() throws Exception {
+ ObjectId ppid = db.resolve("refs/heads/master^");
+ db.writeSymref("HEAD", "refs/heads/unborn");
+ RefUpdate updateRef = db.updateRef("HEAD", true);
+ updateRef.setForceUpdate(true);
+ updateRef.setNewObjectId(ppid);
+ Result update = updateRef.update();
+ assertEquals(Result.NEW, update);
+ assertEquals(ppid, db.resolve("HEAD"));
+ Ref ref = db.getRef("HEAD");
+ assertEquals("HEAD", ref.getName());
+ assertEquals("HEAD", ref.getOrigName());
+
+ // the branch HEAD referred to is left untouched
+ assertNull(db.resolve("refs/heads/unborn"));
+ ReflogReader reflogReader = new ReflogReader(db, "HEAD");
+ org.eclipse.jgit.lib.ReflogReader.Entry e = reflogReader.getReverseEntries().get(0);
+ assertEquals(ObjectId.zeroId(), e.getOldId());
+ assertEquals(ppid, e.getNewId());
+ assertEquals("GIT_COMMITTER_EMAIL", e.getWho().getEmailAddress());
+ assertEquals("GIT_COMMITTER_NAME", e.getWho().getName());
+ assertEquals(1250379778000L, e.getWho().getWhen().getTime());
+ }
+
+ /**
* Delete a ref that exists both as packed and loose. Make sure the ref
* cannot be resolved after delete.
*