Skip to content
Browse files

Ported jgit commit ddaeae3c23bc31f1cc6cd7c8ed343d836c56bed4. Seems th…

…at portions of it have already been ported before.
  • Loading branch information...
1 parent bc2c7e1 commit 3f67e850b941c7523cdd452c55ae5d26eda680eb @nulltoken nulltoken committed
Showing with 66 additions and 0 deletions.
  1. +66 −0 Tests/RefUpdateTest.cs
View
66 Tests/RefUpdateTest.cs
@@ -336,6 +336,72 @@ public void testUpdateRefNoChange()
}
/**
+ * Test case originating from
+ * <a href="http://bugs.eclipse.org/285991">bug 285991</a>
+ *
+ * Make sure the in memory cache is updated properly after
+ * update of symref. This one did not fail because the
+ * ref was packed due to implementation issues.
+ *
+ * @throws Exception
+ */
+ [Test]
+ public void testRefsCacheAfterUpdate()
+ {
+ // Do not use the defalt repo for this case.
+ Dictionary<string, Ref> allRefs = db.getAllRefs();
+ ObjectId oldValue = db.Resolve("HEAD");
+ ObjectId newValue = db.Resolve("HEAD^");
+ // first make HEAD refer to loose ref
+ RefUpdate updateRef = db.UpdateRef(Constants.HEAD);
+ updateRef.IsForceUpdate = true;
+ updateRef.NewObjectId = newValue;
+ RefUpdate.RefUpdateResult update = updateRef.Update();
+ Assert.AreEqual(RefUpdate.RefUpdateResult.Forced, update);
+
+ // now update that ref
+ updateRef = db.UpdateRef(Constants.HEAD);
+ updateRef.IsForceUpdate = true;
+ updateRef.NewObjectId = oldValue;
+ update = updateRef.Update();
+ Assert.AreEqual(RefUpdate.RefUpdateResult.FastForward, update);
+ allRefs = db.getAllRefs();
+ Assert.AreEqual("refs/heads/master", allRefs.GetValue("refs/heads/master").Name);
+ Assert.AreEqual("refs/heads/master", allRefs.GetValue("refs/heads/master").OriginalName);
+ Assert.AreEqual("refs/heads/master", allRefs.GetValue("HEAD").Name);
+ Assert.AreEqual("HEAD", allRefs.GetValue("HEAD").OriginalName);
+ }
+
+ /**
+ * Test case originating from
+ * <a href="http://bugs.eclipse.org/285991">bug 285991</a>
+ *
+ * Make sure the in memory cache is updated properly after
+ * update of symref.
+ *
+ * @throws Exception
+ */
+
+ [Test]
+ public void testRefsCacheAfterUpdateLoosOnly()
+ {
+ // Do not use the defalt repo for this case.
+ Dictionary<string, Ref> allRefs = db.getAllRefs();
+ ObjectId oldValue = db.Resolve("HEAD");
+ db.WriteSymref(Constants.HEAD, "refs/heads/newref");
+ RefUpdate updateRef = db.UpdateRef(Constants.HEAD);
+ updateRef.IsForceUpdate = true;
+ updateRef.NewObjectId = oldValue;
+ RefUpdate.RefUpdateResult update = updateRef.Update();
+ Assert.AreEqual(RefUpdate.RefUpdateResult.New, update);
+ allRefs = db.getAllRefs();
+ Assert.AreEqual("refs/heads/newref", allRefs.GetValue("HEAD").Name);
+ Assert.AreEqual("HEAD", allRefs.GetValue("HEAD").OriginalName);
+ Assert.AreEqual("refs/heads/newref", allRefs.GetValue("refs/heads/newref").Name);
+ Assert.AreEqual("refs/heads/newref", allRefs.GetValue("refs/heads/newref").OriginalName);
+ }
+
+ /**
* Try modify a ref, but get wrong expected old value
*
* @throws IOException

0 comments on commit 3f67e85

Please sign in to comment.
Something went wrong with that request. Please try again.