public void testRenameRefNameColission1avoided() { // setup ObjectId rb = db.Resolve("refs/heads/b"); writeSymref(Constants.HEAD, "refs/heads/a"); RefUpdate updateRef = db.UpdateRef("refs/heads/a"); updateRef.NewObjectId = rb; updateRef.setRefLogMessage("Setup", false); Assert.AreEqual(RefUpdate.RefUpdateResult.FAST_FORWARD, updateRef.update()); ObjectId oldHead = db.Resolve(Constants.HEAD); Assert.IsTrue(rb.Equals(oldHead)); // assumption for this test writeReflog(db, rb, rb, "Just a message", "refs/heads/a"); Assert.IsTrue(new FileInfo(Path.Combine(db.Directory.FullName, "logs/refs/heads/a")).Exists, "internal check, we have a log"); // Now this is our test RefRename renameRef = db.RenameRef("refs/heads/a", "refs/heads/a/b"); RefUpdate.RefUpdateResult result = renameRef.rename(); Assert.AreEqual(RefUpdate.RefUpdateResult.RENAMED, result); Assert.IsNull(db.Resolve("refs/heads/a")); Assert.AreEqual(rb, db.Resolve("refs/heads/a/b")); Assert.AreEqual(3, db.ReflogReader("a/b").getReverseEntries().Count); Assert.AreEqual("Branch: renamed a to a/b", db.ReflogReader("a/b") .getReverseEntries()[0].getComment()); Assert.AreEqual("Just a message", db.ReflogReader("a/b") .getReverseEntries()[1].getComment()); Assert.AreEqual("Setup", db.ReflogReader("a/b").getReverseEntries() [2].getComment()); // same thing was logged to HEAD Assert.AreEqual("Branch: renamed a to a/b", db.ReflogReader("HEAD") .getReverseEntries()[0].getComment()); }
public void testRenameCurrentBranch() { ObjectId rb = db.Resolve("refs/heads/b"); writeSymref(Constants.HEAD, "refs/heads/b"); ObjectId oldHead = db.Resolve(Constants.HEAD); Assert.IsTrue(rb.Equals(oldHead), "internal test condition, b == HEAD"); writeReflog(db, rb, rb, "Just a message", "refs/heads/b"); Assert.IsTrue(new FileInfo(Path.Combine(db.Directory.FullName, "logs/refs/heads/b")).Exists, "log on old branch"); RefRename renameRef = db.RenameRef("refs/heads/b", "refs/heads/new/name"); RefUpdate.RefUpdateResult result = renameRef.rename(); Assert.AreEqual(RefUpdate.RefUpdateResult.RENAMED, result); Assert.AreEqual(rb, db.Resolve("refs/heads/new/name")); Assert.IsNull(db.Resolve("refs/heads/b")); Assert.AreEqual("Branch: renamed b to new/name", db.ReflogReader( "new/name").getLastEntry().getComment()); Assert.IsFalse(new FileInfo(Path.Combine(db.Directory.FullName, "logs/refs/heads/b")).Exists); Assert.AreEqual(rb, db.Resolve(Constants.HEAD)); Assert.AreEqual(2, db.ReflogReader("new/name").getReverseEntries().Count); Assert.AreEqual("Branch: renamed b to new/name", db.ReflogReader("new/name").getReverseEntries()[0].getComment()); Assert.AreEqual("Just a message", db.ReflogReader("new/name").getReverseEntries()[1].getComment()); }
public void tryRenameWhenLocked(string toLock, string fromName, string toName, string headPointsTo) { // setup writeSymref(Constants.HEAD, headPointsTo); ObjectId oldfromId = db.Resolve(fromName); ObjectId oldHeadId = db.Resolve(Constants.HEAD); writeReflog(db, oldfromId, oldfromId, "Just a message", fromName); IList <ReflogReader.Entry> oldFromLog = db .ReflogReader(fromName).getReverseEntries(); IList <ReflogReader.Entry> oldHeadLog = oldHeadId != null?db .ReflogReader(Constants.HEAD).getReverseEntries() : null; Assert.IsTrue(new FileInfo(Path.Combine(db.Directory.FullName, "logs/" + fromName)).Exists, "internal check, we have a log"); // "someone" has branch X locked var lockFile = new LockFile(new FileInfo(Path.Combine(db.Directory.FullName, toLock))); try { Assert.IsTrue(lockFile.Lock()); // Now this is our test RefRename renameRef = db.RenameRef(fromName, toName); RefUpdate.RefUpdateResult result = renameRef.rename(); Assert.AreEqual(RefUpdate.RefUpdateResult.LOCK_FAILURE, result); // Check that the involved refs are the same despite the failure assertExists(false, toName); if (!toLock.Equals(toName)) { assertExists(false, toName + ".lock"); } assertExists(true, toLock + ".lock"); if (!toLock.Equals(fromName)) { assertExists(false, "logs/" + fromName + ".lock"); } assertExists(false, "logs/" + toName + ".lock"); Assert.AreEqual(oldHeadId, db.Resolve(Constants.HEAD)); Assert.AreEqual(oldfromId, db.Resolve(fromName)); Assert.IsNull(db.Resolve(toName)); Assert.AreEqual(oldFromLog.ToString(), db.ReflogReader(fromName) .getReverseEntries().ToString()); if (oldHeadId != null) { Assert.AreEqual(oldHeadLog.ToString(), db.ReflogReader(Constants.HEAD) .getReverseEntries().ToString()); } } finally { lockFile.Unlock(); } }
public void testRenameBranchNoPreviousLog() { Assert.IsFalse(new FileInfo(Path.Combine(db.Directory.FullName, "logs/refs/heads/b")).Exists, "precondition, no log on old branchg"); ObjectId rb = db.Resolve("refs/heads/b"); ObjectId oldHead = db.Resolve(Constants.HEAD); Assert.IsFalse(rb.Equals(oldHead)); // assumption for this test RefRename renameRef = db.RenameRef("refs/heads/b", "refs/heads/new/name"); RefUpdate.RefUpdateResult result = renameRef.rename(); Assert.AreEqual(RefUpdate.RefUpdateResult.RENAMED, result); Assert.AreEqual(rb, db.Resolve("refs/heads/new/name")); Assert.IsNull(db.Resolve("refs/heads/b")); Assert.AreEqual(1, db.ReflogReader("new/name").getReverseEntries().Count); Assert.AreEqual("Branch: renamed b to new/name", db.ReflogReader("new/name") .getLastEntry().getComment()); Assert.IsFalse(new FileInfo(Path.Combine(db.Directory.FullName, "logs/refs/heads/b")).Exists); Assert.AreEqual(oldHead, db.Resolve(Constants.HEAD)); // unchanged }
public void testRenameBranchAlsoInPack() { ObjectId rb = db.Resolve("refs/heads/b"); ObjectId rb2 = db.Resolve("refs/heads/b~1"); Assert.AreEqual(Storage.Packed, db.getRef("refs/heads/b").StorageFormat); RefUpdate updateRef = db.UpdateRef("refs/heads/b"); updateRef.NewObjectId = rb2; updateRef.IsForceUpdate = true; RefUpdate.RefUpdateResult update = updateRef.update(); Assert.AreEqual(RefUpdate.RefUpdateResult.FORCED, update, "internal check new ref is loose"); Assert.AreEqual(Storage.Loose, db.getRef("refs/heads/b").StorageFormat); writeReflog(db, rb, rb, "Just a message", "refs/heads/b"); Assert.IsTrue(new FileInfo(Path.Combine(db.Directory.FullName, "logs/refs/heads/b")).Exists, "log on old branch"); RefRename renameRef = db.RenameRef("refs/heads/b", "refs/heads/new/name"); RefUpdate.RefUpdateResult result = renameRef.rename(); Assert.AreEqual(RefUpdate.RefUpdateResult.RENAMED, result); Assert.AreEqual(rb2, db.Resolve("refs/heads/new/name")); Assert.IsNull(db.Resolve("refs/heads/b")); Assert.AreEqual("Branch: renamed b to new/name", db.ReflogReader( "new/name").getLastEntry().getComment()); Assert.AreEqual(3, db.ReflogReader("refs/heads/new/name").getReverseEntries().Count); Assert.AreEqual("Branch: renamed b to new/name", db.ReflogReader("refs/heads/new/name").getReverseEntries()[0].getComment()); Assert.AreEqual(0, db.ReflogReader("HEAD").getReverseEntries().Count); // make sure b's log file is gone too. Assert.IsFalse(new FileInfo(Path.Combine(db.Directory.FullName, "logs/refs/heads/b")).Exists); // Create new Repository instance, to reread caches and make sure our // assumptions are persistent. using (Core.Repository ndb = new Core.Repository(db.Directory)) { Assert.AreEqual(rb2, ndb.Resolve("refs/heads/new/name")); Assert.IsNull(ndb.Resolve("refs/heads/b")); } }