public void testNoCacheObjectIdSubclass() { string newRef = "refs/heads/abc"; RefUpdate ru = updateRef(newRef); RevCommit newid = new RevCommit(ru.getNewObjectId()) { // empty }; ru.setNewObjectId(newid); RefUpdate.RefUpdateResult update = ru.update(); Assert.AreEqual(RefUpdate.RefUpdateResult.NEW, update); Core.Ref r = db.getAllRefs()[newRef]; Assert.IsNotNull(r); Assert.AreEqual(newRef, r.Name); Assert.IsNotNull(r.ObjectId); Assert.AreNotSame(newid, r.ObjectId); Assert.AreSame(typeof(ObjectId), r.ObjectId.GetType()); Assert.AreEqual(newid.Copy(), r.ObjectId); IList <ReflogReader.Entry> reverseEntries1 = db.ReflogReader("refs/heads/abc").getReverseEntries(); ReflogReader.Entry entry1 = reverseEntries1[0]; Assert.AreEqual(1, reverseEntries1.Count); Assert.AreEqual(ObjectId.ZeroId, entry1.getOldId()); Assert.AreEqual(r.ObjectId, entry1.getNewId()); Assert.AreEqual(new PersonIdent(db).ToString(), entry1.getWho().ToString()); Assert.AreEqual("", entry1.getComment()); IList <ReflogReader.Entry> reverseEntries2 = db.ReflogReader("HEAD").getReverseEntries(); Assert.AreEqual(0, reverseEntries2.Count); }
public void testUpdateRefDetachedUnbornHead() { ObjectId ppid = db.Resolve("refs/heads/master^"); writeSymref("HEAD", "refs/heads/unborn"); RefUpdate updateRef = db.UpdateRef("HEAD", true); updateRef.IsForceUpdate = true; updateRef.NewObjectId = ppid; RefUpdate.RefUpdateResult update = updateRef.update(); Assert.AreEqual(RefUpdate.RefUpdateResult.NEW, update); Assert.AreEqual(ppid, db.Resolve("HEAD")); Ref @ref = db.getRef("HEAD"); Assert.AreEqual("HEAD", @ref.Name); Assert.IsTrue([email protected](), "is detached"); // the branch HEAD referred to is left untouched Assert.IsNull(db.Resolve("refs/heads/unborn")); ReflogReader reflogReader = new ReflogReader(db, "HEAD"); ReflogReader.Entry e = reflogReader.getReverseEntries()[0]; Assert.AreEqual(ObjectId.ZeroId, e.getOldId()); Assert.AreEqual(ppid, e.getNewId()); Assert.AreEqual("GIT_COMMITTER_EMAIL", e.getWho().EmailAddress); Assert.AreEqual("GIT_COMMITTER_NAME", e.getWho().Name); Assert.AreEqual(1250379778000L, e.getWho().When); }
public void testRefsCacheAfterUpdate() { // Do not use the defalt repo for this case. Dictionary <string, Core.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); }
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 testNewNamespaceConflictWithLoosePrefixOfExisting() { string newRef = "refs/heads/z/a"; RefUpdate ru = updateRef(newRef); RevCommit newid = new RevCommit(ru.NewObjectId) { // empty }; ru.NewObjectId = newid; RefUpdate.RefUpdateResult update = ru.update(); Assert.AreEqual(RefUpdate.RefUpdateResult.NEW, update); // end setup string newRef2 = "refs/heads/z"; RefUpdate ru2 = updateRef(newRef2); RevCommit newid2 = new RevCommit(ru2.NewObjectId) { // empty }; ru.NewObjectId = newid2; RefUpdate.RefUpdateResult update2 = ru2.update(); Assert.AreEqual(RefUpdate.RefUpdateResult.LOCK_FAILURE, update2); Assert.AreEqual(1, db.ReflogReader("refs/heads/z/a").getReverseEntries().Count); Assert.IsNull(db.ReflogReader("refs/heads/z")); Assert.AreEqual(0, db.ReflogReader("HEAD").getReverseEntries().Count); }
private static void Status(ReceiveCommand cmd, RefUpdate.RefUpdateResult result) { switch (result) { case RefUpdate.RefUpdateResult.NotAttempted: cmd.setResult(ReceiveCommand.Result.NOT_ATTEMPTED); break; case RefUpdate.RefUpdateResult.LockFailure: case RefUpdate.RefUpdateResult.IOFailure: cmd.setResult(ReceiveCommand.Result.LOCK_FAILURE); break; case RefUpdate.RefUpdateResult.NoChange: case RefUpdate.RefUpdateResult.New: case RefUpdate.RefUpdateResult.Forced: case RefUpdate.RefUpdateResult.FastForward: cmd.setResult(ReceiveCommand.Result.OK); break; case RefUpdate.RefUpdateResult.Rejected: cmd.setResult(ReceiveCommand.Result.REJECTED_NONFASTFORWARD); break; case RefUpdate.RefUpdateResult.RejectedCurrentBranch: cmd.setResult(ReceiveCommand.Result.REJECTED_CURRENT_BRANCH); break; default: cmd.setResult(ReceiveCommand.Result.REJECTED_OTHER_REASON, result.ToString()); break; } }
private static void Status(ReceiveCommand cmd, RefUpdate.RefUpdateResult result) { switch (result) { case RefUpdate.RefUpdateResult.NOT_ATTEMPTED: cmd.setResult(ReceiveCommand.Result.NOT_ATTEMPTED); break; case RefUpdate.RefUpdateResult.LOCK_FAILURE: case RefUpdate.RefUpdateResult.IO_FAILURE: cmd.setResult(ReceiveCommand.Result.LOCK_FAILURE); break; case RefUpdate.RefUpdateResult.NO_CHANGE: case RefUpdate.RefUpdateResult.NEW: case RefUpdate.RefUpdateResult.FORCED: case RefUpdate.RefUpdateResult.FAST_FORWARD: cmd.setResult(ReceiveCommand.Result.OK); break; case RefUpdate.RefUpdateResult.REJECTED: cmd.setResult(ReceiveCommand.Result.REJECTED_NONFASTFORWARD); break; case RefUpdate.RefUpdateResult.REJECTED_CURRENT_BRANCH: cmd.setResult(ReceiveCommand.Result.REJECTED_CURRENT_BRANCH); break; default: cmd.setResult(ReceiveCommand.Result.REJECTED_OTHER_REASON, Enum.GetName(typeof(RefUpdate.RefUpdateResult), result)); break; } }
public void testRefsCacheAfterUpdate() { // Do not use the defalt repo for this case. IDictionary <string, Core.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.FAST_FORWARD, update); allRefs = db.getAllRefs(); Ref master = allRefs.GetValue("refs/heads/master"); Ref head = allRefs.GetValue("HEAD"); Assert.AreEqual("refs/heads/master", master.Name); Assert.AreEqual("HEAD", head.Name); Assert.IsTrue(head.isSymbolic(), "is symbolic reference"); Assert.AreSame(master, head.getTarget()); }
private void delete(RefUpdate @ref, RefUpdate.RefUpdateResult expected, bool exists, bool removed) { Assert.AreEqual(exists, db.getAllRefs().ContainsKey(@ref.getName())); Assert.AreEqual(expected, @ref.delete()); Assert.AreEqual(!removed, db.getAllRefs().ContainsKey(@ref.getName())); }
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 testReadLooseRef() { RefUpdate updateRef = db.UpdateRef("ref/heads/new"); updateRef.NewObjectId = db.Resolve("refs/heads/master"); RefUpdate.RefUpdateResult update = updateRef.Update(); Assert.AreEqual(RefUpdate.RefUpdateResult.New, update); Core.Ref @ref = db.getRef("ref/heads/new"); Assert.AreEqual(Core.Ref.Storage.Loose, @ref.StorageFormat); }
/// <returns>the result of the new ref update</returns> public RefUpdate.RefUpdateResult rename() { try { result = doRename(); return(result); } catch (IOException) { result = RefUpdate.RefUpdateResult.IO_FAILURE; throw; } }
public void testReadLooseRef() { RefUpdate updateRef = db.UpdateRef("ref/heads/new"); updateRef.setNewObjectId(db.Resolve("refs/heads/master")); RefUpdate.RefUpdateResult update = updateRef.update(); Assert.AreEqual(RefUpdate.RefUpdateResult.NEW, update); global::GitSharp.Core.Ref @ref = db.getRef("ref/heads/new"); Assert.AreEqual(Storage.Loose, @ref.StorageFormat); }
public void testUpdateRefNoChange() { ObjectId pid = db.Resolve("refs/heads/master"); RefUpdate updateRef = db.UpdateRef("refs/heads/master"); updateRef.NewObjectId = pid; RefUpdate.RefUpdateResult update = updateRef.update(); Assert.AreEqual(RefUpdate.RefUpdateResult.NO_CHANGE, update); Assert.AreEqual(pid, db.Resolve("refs/heads/master")); }
private string longTypeOf(TrackingRefUpdate u) { RefUpdate.RefUpdateResult r = u.Result; if (r == RefUpdate.RefUpdateResult.LockFailure) { return("[lock fail]"); } if (r == RefUpdate.RefUpdateResult.IOFailure) { return("[i/o error]"); } if (r == RefUpdate.RefUpdateResult.Rejected) { return("[rejected]"); } if (ObjectId.ZeroId.Equals(u.NewObjectId)) { return("[deleted]"); } if (r == RefUpdate.RefUpdateResult.New) { if (u.RemoteName.StartsWith(Constants.R_HEADS)) { return("[new branch]"); } if (u.LocalName.StartsWith(Constants.R_TAGS)) { return("[new tag]"); } return("[new]"); } if (r == RefUpdate.RefUpdateResult.Forced) { string aOld = u.OldObjectId.Abbreviate(Repository._internal_repo).name(); string aNew = u.NewObjectId.Abbreviate(Repository._internal_repo).name(); return(aOld + "..." + aNew); } if (r == RefUpdate.RefUpdateResult.FastForward) { string aOld = u.OldObjectId.Abbreviate(Repository._internal_repo).name(); string aNew = u.NewObjectId.Abbreviate(Repository._internal_repo).name(); return(aOld + ".." + aNew); } if (r == RefUpdate.RefUpdateResult.NoChange) { return("[up to date]"); } return("[" + r + "]"); }
private string longTypeOf(TrackingRefUpdate u) { RefUpdate.RefUpdateResult r = u.Result; if (r == RefUpdate.RefUpdateResult.LOCK_FAILURE) { return("[lock fail]"); } if (r == RefUpdate.RefUpdateResult.IO_FAILURE) { return("[i/o error]"); } if (r == RefUpdate.RefUpdateResult.REJECTED) { return("[rejected]"); } if (ObjectId.ZeroId.Equals(u.NewObjectId)) { return("[deleted]"); } if (r == RefUpdate.RefUpdateResult.NEW) { if (u.RemoteName.StartsWith(Constants.R_HEADS)) { return("[new branch]"); } if (u.LocalName.StartsWith(Constants.R_TAGS)) { return("[new tag]"); } return("[new]"); } if (r == RefUpdate.RefUpdateResult.FORCED) { string aOld = u.OldObjectId.Abbreviate(Repository).name(); string aNew = u.NewObjectId.Abbreviate(Repository).name(); return(aOld + "..." + aNew); } if (r == RefUpdate.RefUpdateResult.FAST_FORWARD) { string aOld = u.OldObjectId.Abbreviate(Repository).name(); string aNew = u.NewObjectId.Abbreviate(Repository).name(); return(aOld + ".." + aNew); } if (r == RefUpdate.RefUpdateResult.NO_CHANGE) { return("[up to date]"); } return("[" + r + "]"); }
public void testUpdateRefLockFailureWrongOldValue() { ObjectId pid = db.Resolve("refs/heads/master"); RefUpdate updateRef = db.UpdateRef("refs/heads/master"); updateRef.NewObjectId = pid; updateRef.ExpectedOldObjectId = db.Resolve("refs/heads/master^"); RefUpdate.RefUpdateResult update = updateRef.update(); Assert.AreEqual(RefUpdate.RefUpdateResult.LOCK_FAILURE, update); Assert.AreEqual(pid, db.Resolve("refs/heads/master")); }
public void testDeleteLoosePackedRejected() { ObjectId pid = db.Resolve("refs/heads/c^"); ObjectId oldpid = db.Resolve("refs/heads/c"); RefUpdate updateRef = db.UpdateRef("refs/heads/c"); updateRef.NewObjectId = pid; RefUpdate.RefUpdateResult update = updateRef.update(); Assert.AreEqual(RefUpdate.RefUpdateResult.REJECTED, update); Assert.AreEqual(oldpid, db.Resolve("refs/heads/c")); }
public void testReadSymRefToLoosePacked() { ObjectId pid = db.Resolve("refs/heads/master^"); RefUpdate updateRef = db.UpdateRef("refs/heads/master"); updateRef.NewObjectId = pid; updateRef.IsForceUpdate = true; RefUpdate.RefUpdateResult update = updateRef.Update(); Assert.AreEqual(RefUpdate.RefUpdateResult.Forced, update); // internal db.WriteSymref("HEAD", "refs/heads/master"); Core.Ref @ref = db.getRef("HEAD"); Assert.AreEqual(Core.Ref.Storage.LoosePacked, @ref.StorageFormat); }
public void testNewNamespaceConflictWithPackedPrefixOfExisting() { string newRef = "refs/heads/prefix"; RefUpdate ru = updateRef(newRef); RevCommit newid = new RevCommit(ru.NewObjectId) { // empty }; ru.NewObjectId = newid; RefUpdate.RefUpdateResult update = ru.update(); Assert.AreEqual(RefUpdate.RefUpdateResult.LOCK_FAILURE, update); Assert.IsNull(db.ReflogReader("refs/heads/prefix")); Assert.AreEqual(0, db.ReflogReader("HEAD").getReverseEntries().Count); }
public void testReadSimplePackedRefSameRepo() { Core.Ref @ref = db.getRef("refs/heads/master"); ObjectId pid = db.Resolve("refs/heads/master^"); Assert.AreEqual(Core.Ref.Storage.Packed, @ref.StorageFormat); RefUpdate updateRef = db.UpdateRef("refs/heads/master"); updateRef.NewObjectId = pid; updateRef.IsForceUpdate = true; RefUpdate.RefUpdateResult update = updateRef.Update(); Assert.AreEqual(RefUpdate.RefUpdateResult.Forced, update); @ref = db.getRef("refs/heads/master"); Assert.AreEqual(Core.Ref.Storage.LoosePacked, @ref.StorageFormat); }
public void testReadSimplePackedRefSameRepo() { global::GitSharp.Core.Ref @ref = db.getRef("refs/heads/master"); ObjectId pid = db.Resolve("refs/heads/master^"); Assert.AreEqual(Storage.Packed, @ref.StorageFormat); RefUpdate updateRef = db.UpdateRef("refs/heads/master"); updateRef.setNewObjectId(pid); updateRef.setForceUpdate(true); RefUpdate.RefUpdateResult update = updateRef.update(); Assert.AreEqual(RefUpdate.RefUpdateResult.FORCED, update); @ref = db.getRef("refs/heads/master"); Assert.AreEqual(Storage.Loose, @ref.StorageFormat); }
public void testReadSymRefToLoosePacked() { ObjectId pid = db.Resolve("refs/heads/master^"); RefUpdate updateRef = db.UpdateRef("refs/heads/master"); updateRef.setNewObjectId(pid); updateRef.setForceUpdate(true); RefUpdate.RefUpdateResult update = updateRef.update(); Assert.AreEqual(RefUpdate.RefUpdateResult.FORCED, update); // internal writeSymref("HEAD", "refs/heads/master"); global::GitSharp.Core.Ref @ref = db.getRef("HEAD"); Assert.AreEqual(Storage.Loose, @ref.StorageFormat); @ref = @ref.getTarget(); Assert.AreEqual("refs/heads/master", @ref.Name); Assert.AreEqual(Storage.Loose, @ref.StorageFormat); }
public void testDeleteLoosePacked() { ObjectId pid = db.Resolve("refs/heads/c^"); RefUpdate updateRef = db.UpdateRef("refs/heads/c"); updateRef.NewObjectId = pid; updateRef.IsForceUpdate = true; RefUpdate.RefUpdateResult update = updateRef.update(); Assert.AreEqual(RefUpdate.RefUpdateResult.FORCED, update); // internal // The real test here RefUpdate updateRef2 = db.UpdateRef("refs/heads/c"); updateRef2.IsForceUpdate = true; RefUpdate.RefUpdateResult delete = updateRef2.delete(); Assert.AreEqual(RefUpdate.RefUpdateResult.FORCED, delete); Assert.IsNull(db.Resolve("refs/heads/c")); }
public void testDeleteHEADreferencedRef() { ObjectId pid = db.Resolve("refs/heads/master^"); RefUpdate updateRef = db.UpdateRef("refs/heads/master"); updateRef.NewObjectId = pid; updateRef.IsForceUpdate = true; RefUpdate.RefUpdateResult update = updateRef.update(); Assert.AreEqual(RefUpdate.RefUpdateResult.FORCED, update); // internal RefUpdate updateRef2 = db.UpdateRef("refs/heads/master"); RefUpdate.RefUpdateResult delete = updateRef2.delete(); Assert.AreEqual(RefUpdate.RefUpdateResult.REJECTED_CURRENT_BRANCH, delete); Assert.AreEqual(pid, db.Resolve("refs/heads/master")); Assert.AreEqual(1, db.ReflogReader("refs/heads/master").getReverseEntries().Count); Assert.AreEqual(0, db.ReflogReader("HEAD").getReverseEntries().Count); }
public void testRefsCacheAfterUpdateLoosOnly() { // Do not use the defalt repo for this case. Dictionary <string, Core.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); }
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 testUpdateRefForward() { ObjectId ppid = db.Resolve("refs/heads/master^"); ObjectId pid = db.Resolve("refs/heads/master"); RefUpdate updateRef = db.UpdateRef("refs/heads/master"); updateRef.NewObjectId = ppid; updateRef.IsForceUpdate = true; RefUpdate.RefUpdateResult update = updateRef.update(); Assert.AreEqual(RefUpdate.RefUpdateResult.FORCED, update); Assert.AreEqual(ppid, db.Resolve("refs/heads/master")); // real test RefUpdate updateRef2 = db.UpdateRef("refs/heads/master"); updateRef2.NewObjectId = pid; RefUpdate.RefUpdateResult update2 = updateRef2.update(); Assert.AreEqual(RefUpdate.RefUpdateResult.FAST_FORWARD, update2); Assert.AreEqual(pid, db.Resolve("refs/heads/master")); }
private static char shortTypeOf(RefUpdate.RefUpdateResult r) { switch (r) { case RefUpdate.RefUpdateResult.LockFailure: case RefUpdate.RefUpdateResult.IOFailure: case RefUpdate.RefUpdateResult.Rejected: return('!'); case RefUpdate.RefUpdateResult.New: return('*'); case RefUpdate.RefUpdateResult.Forced: return('+'); case RefUpdate.RefUpdateResult.NoChange: return('='); default: return(' '); } }
/// <returns>the result of the new ref update</returns> public RefUpdate.RefUpdateResult rename() { try { result = doRename(); return result; } catch (IOException) { result = RefUpdate.RefUpdateResult.IO_FAILURE; throw; } }