private void doCheckout(GitSharp.Core.Ref branch) { if (branch == null) { throw new ArgumentNullException("branch", "Cannot checkout; no HEAD advertised by remote"); } var repo = Repository._internal_repo; if (!Constants.HEAD.Equals(branch.getName())) { RefUpdate u1 = repo.UpdateRef(Constants.HEAD); u1.disableRefLog(); u1.link(branch.getName()); } GitSharp.Core.Commit commit = repo.MapCommit(branch.ObjectId); RefUpdate u = repo.UpdateRef(Constants.HEAD); u.NewObjectId = commit.CommitId; u.forceUpdate(); GitIndex index = new GitIndex(repo); GitSharp.Core.Tree tree = commit.TreeEntry; WorkDirCheckout co = new WorkDirCheckout(repo, repo.WorkingDirectory, index, tree); co.checkout(); index.write(); }
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); }
/// <summary>Write the given ref update to the ref's log</summary> /// <param name="update"></param> /// <param name="msg"></param> /// <param name="deref"></param> /// <returns>this writer</returns> /// <exception cref="System.IO.IOException">System.IO.IOException</exception> public virtual NGit.Storage.File.ReflogWriter Log(RefUpdate update, string msg, bool deref) { ObjectId oldId = update.GetOldObjectId(); ObjectId newId = update.GetNewObjectId(); Ref @ref = update.GetRef(); PersonIdent ident = update.GetRefLogIdent(); if (ident == null) { ident = new PersonIdent(parent); } else { ident = new PersonIdent(ident); } byte[] rec = Encode(oldId, newId, ident, msg); if (deref && @ref.IsSymbolic()) { Log(@ref.GetName(), rec); Log(@ref.GetLeaf().GetName(), rec); } else { Log(@ref.GetName(), rec); } return(this); }
/// <exception cref="System.IO.IOException"></exception> private void CommitNoteMap(RevWalk walk, NoteMap map, RevCommit notesCommit, ObjectInserter inserter, string msg) { // commit the note NGit.CommitBuilder builder = new NGit.CommitBuilder(); builder.TreeId = map.WriteTree(inserter); builder.Author = new PersonIdent(repo); builder.Committer = builder.Author; builder.Message = msg; if (notesCommit != null) { builder.SetParentIds(notesCommit); } ObjectId commit = inserter.Insert(builder); inserter.Flush(); RefUpdate refUpdate = repo.UpdateRef(notesRef); if (notesCommit != null) { refUpdate.SetExpectedOldObjectId(notesCommit); } else { refUpdate.SetExpectedOldObjectId(ObjectId.ZeroId); } refUpdate.SetNewObjectId(commit); refUpdate.Update(walk); }
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 test028_LockPackedRef() { writeTrashFile(".git/packed-refs", "7f822839a2fe9760f386cbbbcb3f92c5fe81def7 refs/heads/foobar"); writeTrashFile(".git/HEAD", "ref: refs/heads/foobar\n"); BUG_WorkAroundRacyGitIssues("packed-refs"); BUG_WorkAroundRacyGitIssues("HEAD"); ObjectId resolve = db.Resolve("HEAD"); Assert.AreEqual("7f822839a2fe9760f386cbbbcb3f92c5fe81def7", resolve.Name); RefUpdate lockRef = db.UpdateRef("HEAD"); ObjectId newId = ObjectId.FromString("07f822839a2fe9760f386cbbbcb3f92c5fe81def"); lockRef.NewObjectId = newId; Assert.AreEqual(RefUpdate.RefUpdateResult.FORCED, lockRef.forceUpdate()); Assert.IsTrue(new FileInfo(db.Directory.FullName + "/refs/heads/foobar").Exists); Assert.AreEqual(newId, db.Resolve("refs/heads/foobar")); // Again. The ref already exists RefUpdate lockRef2 = db.UpdateRef("HEAD"); ObjectId newId2 = ObjectId.FromString("7f822839a2fe9760f386cbbbcb3f92c5fe81def7"); lockRef2.NewObjectId = newId2; Assert.AreEqual(RefUpdate.RefUpdateResult.FORCED, lockRef2.forceUpdate()); Assert.IsTrue(new FileInfo(db.Directory.FullName + "/refs/heads/foobar").Exists); Assert.AreEqual(newId2, db.Resolve("refs/heads/foobar")); }
/// <exception cref="System.IO.IOException"></exception> private RebaseResult Abort(RebaseResult result) { try { string commitId = ReadFile(repo.Directory, Constants.ORIG_HEAD); monitor.BeginTask(MessageFormat.Format(JGitText.Get().abortingRebase, commitId), ProgressMonitor.UNKNOWN); DirCacheCheckout dco; RevCommit commit = walk.ParseCommit(repo.Resolve(commitId)); if (result.GetStatus().Equals(RebaseResult.Status.FAILED)) { RevCommit head = walk.ParseCommit(repo.Resolve(Constants.HEAD)); dco = new DirCacheCheckout(repo, head.Tree, repo.LockDirCache(), commit.Tree); } else { dco = new DirCacheCheckout(repo, repo.LockDirCache(), commit.Tree); } dco.SetFailOnConflict(false); dco.Checkout(); walk.Release(); } finally { monitor.EndTask(); } try { string headName = ReadFile(rebaseDir, HEAD_NAME); if (headName.StartsWith(Constants.R_REFS)) { monitor.BeginTask(MessageFormat.Format(JGitText.Get().resettingHead, headName), ProgressMonitor .UNKNOWN); // update the HEAD RefUpdate refUpdate = repo.UpdateRef(Constants.HEAD, false); RefUpdate.Result res = refUpdate.Link(headName); switch (res) { case RefUpdate.Result.FAST_FORWARD: case RefUpdate.Result.FORCED: case RefUpdate.Result.NO_CHANGE: { break; } default: { throw new JGitInternalException(JGitText.Get().abortingRebaseFailed); } } } // cleanup the files FileUtils.Delete(rebaseDir, FileUtils.RECURSIVE); return(result); } finally { monitor.EndTask(); } }
private RefUpdate updateRef(string name) { RefUpdate @ref = db.UpdateRef(name); @ref.setNewObjectId(db.Resolve(Constants.HEAD)); return(@ref); }
public override void Setup() { // Generate directories and a svn util. rootUrl = new FilePath(FileService.CreateTempDirectory() + Path.DirectorySeparatorChar); rootCheckout = new FilePath(FileService.CreateTempDirectory() + Path.DirectorySeparatorChar); Directory.CreateDirectory(rootUrl.FullPath + "repo.git"); repoLocation = "file:///" + rootUrl.FullPath + "repo.git"; // Initialize the bare repo. InitCommand ci = new InitCommand(); ci.SetDirectory(new Sharpen.FilePath(rootUrl.FullPath + "repo.git")); ci.SetBare(true); ci.Call(); FileRepository bare = new FileRepository(new Sharpen.FilePath(rootUrl.FullPath + "repo.git")); string branch = Constants.R_HEADS + "master"; RefUpdate head = bare.UpdateRef(Constants.HEAD); head.DisableRefLog(); head.Link(branch); // Check out the repository. Checkout(rootCheckout, repoLocation); repo = GetRepo(rootCheckout, repoLocation); DOT_DIR = ".git"; }
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())); }
/// <exception cref="System.IO.IOException"></exception> private void Delete(RefUpdate @ref, RefUpdate.Result expected, bool exists, bool removed) { NUnit.Framework.Assert.AreEqual(exists, db.GetAllRefs().ContainsKey(@ref.GetName())); NUnit.Framework.Assert.AreEqual(expected, @ref.Delete()); NUnit.Framework.Assert.AreEqual(!removed, db.GetAllRefs().ContainsKey(@ref.GetName())); }
public virtual void TestUpdateRefLockFailureLocked() { ObjectId opid = db.Resolve("refs/heads/master"); ObjectId pid = db.Resolve("refs/heads/master^"); RefUpdate updateRef = db.UpdateRef("refs/heads/master"); updateRef.SetNewObjectId(pid); LockFile lockFile1 = new LockFile(new FilePath(db.Directory, "refs/heads/master") , db.FileSystem); try { NUnit.Framework.Assert.IsTrue(lockFile1.Lock()); // precondition to test RefUpdate.Result update = updateRef.Update(); NUnit.Framework.Assert.AreEqual(RefUpdate.Result.LOCK_FAILURE, update); NUnit.Framework.Assert.AreEqual(opid, db.Resolve("refs/heads/master")); LockFile lockFile2 = new LockFile(new FilePath(db.Directory, "refs/heads/master") , db.FileSystem); NUnit.Framework.Assert.IsFalse(lockFile2.Lock()); } finally { // was locked, still is lockFile1.Unlock(); } }
public virtual void TestRefsCacheAfterUpdate() { // Do not use the defalt repo for this case. IDictionary <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.SetForceUpdate(true); updateRef.SetNewObjectId(newValue); RefUpdate.Result update = updateRef.Update(); NUnit.Framework.Assert.AreEqual(RefUpdate.Result.FORCED, update); // now update that ref updateRef = db.UpdateRef(Constants.HEAD); updateRef.SetForceUpdate(true); updateRef.SetNewObjectId(oldValue); update = updateRef.Update(); NUnit.Framework.Assert.AreEqual(RefUpdate.Result.FAST_FORWARD, update); allRefs = db.GetAllRefs(); Ref master = allRefs.Get("refs/heads/master"); Ref head = allRefs.Get("HEAD"); NUnit.Framework.Assert.AreEqual("refs/heads/master", master.GetName()); NUnit.Framework.Assert.AreEqual("HEAD", head.GetName()); NUnit.Framework.Assert.IsTrue(head.IsSymbolic(), "is symbolic reference"); NUnit.Framework.Assert.AreSame(master, head.GetTarget()); }
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); }
private void UpdateRef(Ref stashRef, ObjectId newId) { try { RefUpdate update = CreateRefUpdate(stashRef); update.SetNewObjectId(newId); RefUpdate.Result result = update.Update(); switch (result) { case RefUpdate.Result.FORCED: case RefUpdate.Result.NEW: case RefUpdate.Result.NO_CHANGE: { return; } default: { throw new JGitInternalException(MessageFormat.Format(JGitText.Get().updatingRefFailed , Constants.R_STASH, newId, result)); } } } catch (IOException e) { throw new JGitInternalException(JGitText.Get().stashDropFailed, e); } }
public override void Setup() { // Generate directories and a svn util. RemotePath = new FilePath(FileService.CreateTempDirectory() + Path.DirectorySeparatorChar); LocalPath = new FilePath(FileService.CreateTempDirectory() + Path.DirectorySeparatorChar); Directory.CreateDirectory(RemotePath.FullPath + "repo.git"); RemoteUrl = "file:///" + RemotePath.FullPath + "repo.git"; // Initialize the bare repo. var ci = new InitCommand(); ci.SetDirectory(new Sharpen.FilePath(RemotePath.FullPath + "repo.git")); ci.SetBare(true); ci.Call(); var bare = new FileRepository(new Sharpen.FilePath(RemotePath.FullPath + "repo.git")); string branch = Constants.R_HEADS + "master"; RefUpdate head = bare.UpdateRef(Constants.HEAD); head.DisableRefLog(); head.Link(branch); // Check out the repository. Checkout(LocalPath, RemoteUrl); Repo = GetRepo(LocalPath, RemoteUrl); DotDir = ".git"; }
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()); }
/// <exception cref="System.IO.IOException"></exception> private void CheckoutCommit(RevCommit commit) { try { RevCommit head = walk.ParseCommit(repo.Resolve(Constants.HEAD)); DirCacheCheckout dco = new DirCacheCheckout(repo, head.Tree, repo.LockDirCache(), commit.Tree); dco.SetFailOnConflict(true); dco.Checkout(); // update the HEAD RefUpdate refUpdate = repo.UpdateRef(Constants.HEAD, true); refUpdate.SetExpectedOldObjectId(head); refUpdate.SetNewObjectId(commit); RefUpdate.Result res = refUpdate.ForceUpdate(); switch (res) { case RefUpdate.Result.FAST_FORWARD: case RefUpdate.Result.NO_CHANGE: case RefUpdate.Result.FORCED: { break; } default: { throw new IOException("Could not rewind to upstream commit"); } } } finally { walk.Release(); monitor.EndTask(); } }
/// <exception cref="System.IO.IOException"></exception> /// <exception cref="NGit.Api.Errors.ConcurrentRefUpdateException"></exception> private void UpdateHead(StringBuilder refLogMessage, ObjectId newHeadId, ObjectId oldHeadID) { RefUpdate refUpdate = repo.UpdateRef(Constants.HEAD); refUpdate.SetNewObjectId(newHeadId); refUpdate.SetRefLogMessage(refLogMessage.ToString(), false); refUpdate.SetExpectedOldObjectId(oldHeadID); RefUpdate.Result rc = refUpdate.Update(); switch (rc) { case RefUpdate.Result.NEW: case RefUpdate.Result.FAST_FORWARD: { return; } case RefUpdate.Result.REJECTED: case RefUpdate.Result.LOCK_FAILURE: { throw new ConcurrentRefUpdateException(JGitText.Get().couldNotLockHEAD, refUpdate .GetRef(), rc); } default: { throw new JGitInternalException(MessageFormat.Format(JGitText.Get().updatingRefFailed , Constants.HEAD, newHeadId.ToString(), rc)); } } }
public static LocalGitRepository Init(string targetLocalPath, string url) { InitCommand ci = new InitCommand(); ci.SetDirectory(targetLocalPath); ci.Call(); LocalGitRepository repo = new LocalGitRepository(Path.Combine(targetLocalPath, Constants.DOT_GIT)); string branch = Constants.R_HEADS + "master"; RefUpdate head = repo.UpdateRef(Constants.HEAD); head.DisableRefLog(); head.Link(branch); if (url != null) { RemoteConfig remoteConfig = new RemoteConfig(repo.GetConfig(), "origin"); remoteConfig.AddURI(new URIish(url)); string dst = Constants.R_REMOTES + remoteConfig.Name; RefSpec wcrs = new RefSpec(); wcrs = wcrs.SetForceUpdate(true); wcrs = wcrs.SetSourceDestination(Constants.R_HEADS + "*", dst + "/*"); remoteConfig.AddFetchRefSpec(wcrs); remoteConfig.Update(repo.GetConfig()); } // we're setting up for a clone with a checkout repo.GetConfig().SetBoolean("core", null, "bare", false); repo.GetConfig().Save(); return(repo); }
private bool RenameLog(RefUpdate src, RefUpdate dst) { FilePath srcLog = refdb.GetLogWriter().LogFor(src.GetName()); FilePath dstLog = refdb.GetLogWriter().LogFor(dst.GetName()); if (!srcLog.Exists()) { return(true); } if (!Rename(srcLog, dstLog)) { return(false); } try { int levels = RefDirectory.LevelsIn(src.GetName()) - 2; RefDirectory.Delete(srcLog, levels); return(true); } catch (IOException) { Rename(dstLog, srcLog); return(false); } }
private bool LinkHEAD(RefUpdate target) { try { RefUpdate u = ((RefDirectoryUpdate)refdb.NewUpdate(Constants.HEAD, false)); u.DisableRefLog(); switch (u.Link(target.GetName())) { case RefUpdate.Result.NEW: case RefUpdate.Result.FORCED: case RefUpdate.Result.NO_CHANGE: { return(true); } default: { return(false); break; } } } catch (IOException) { return(false); } }
public virtual void TestMergeEmptyBranches() { Git git = new Git(db); git.Commit().SetMessage("initial commit").Call(); RefUpdate r = db.UpdateRef("refs/heads/side"); r.SetNewObjectId(db.Resolve(Constants.HEAD)); NUnit.Framework.Assert.AreEqual(r.ForceUpdate(), RefUpdate.Result.NEW); RevCommit second = git.Commit().SetMessage("second commit").SetCommitter(committer ).Call(); db.UpdateRef(Constants.HEAD).Link("refs/heads/side"); RevCommit firstSide = git.Commit().SetMessage("first side commit").SetAuthor(author ).Call(); Write(new FilePath(db.Directory, Constants.MERGE_HEAD), ObjectId.ToString(db.Resolve ("refs/heads/master"))); Write(new FilePath(db.Directory, Constants.MERGE_MSG), "merging"); RevCommit commit = git.Commit().Call(); RevCommit[] parents = commit.Parents; NUnit.Framework.Assert.AreEqual(parents[0], firstSide); NUnit.Framework.Assert.AreEqual(parents[1], second); NUnit.Framework.Assert.IsTrue(parents.Length == 2); }
/// <exception cref="NGit.Api.Errors.JGitInternalException"></exception> /// <exception cref="NGit.Errors.MissingObjectException"></exception> /// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception> /// <exception cref="System.IO.IOException"></exception> private void Checkout(Repository repo, FetchResult result) { if (branch.StartsWith(Constants.R_HEADS)) { RefUpdate head = repo.UpdateRef(Constants.HEAD); head.DisableRefLog(); head.Link(branch); } Ref head_1 = result.GetAdvertisedRef(branch); if (head_1 == null || head_1.GetObjectId() == null) { return; } // throw exception? RevCommit commit = ParseCommit(repo, head_1); bool detached = !head_1.GetName().StartsWith(Constants.R_HEADS); RefUpdate u = repo.UpdateRef(Constants.HEAD, detached); u.SetNewObjectId(commit.Id); u.ForceUpdate(); if (!bare) { DirCache dc = repo.LockDirCache(); DirCacheCheckout co = new DirCacheCheckout(repo, dc, commit.Tree); co.Checkout(); } }
public virtual void testReadAllIncludingSymrefs() { ObjectId masterId = db.Resolve("refs/heads/master"); RefUpdate updateRef = db.UpdateRef("refs/remotes/origin/master"); updateRef.setNewObjectId(masterId); updateRef.setForceUpdate(true); updateRef.update(); writeSymref("refs/remotes/origin/HEAD", "refs/remotes/origin/master"); ObjectId r = db.Resolve("refs/remotes/origin/HEAD"); Assert.AreEqual(masterId, r); IDictionary <string, global::GitSharp.Core.Ref> allRefs = db.getAllRefs(); global::GitSharp.Core.Ref refHEAD = allRefs["refs/remotes/origin/HEAD"]; Assert.IsNotNull(refHEAD); Assert.AreEqual(masterId, refHEAD.ObjectId); Assert.IsFalse(refHEAD.IsPeeled); Assert.IsNull(refHEAD.PeeledObjectId); global::GitSharp.Core.Ref refmaster = allRefs["refs/remotes/origin/master"]; Assert.AreEqual(masterId, refmaster.ObjectId); Assert.IsFalse(refmaster.IsPeeled); Assert.IsNull(refmaster.PeeledObjectId); }
/// <exception cref="System.IO.IOException"></exception> private void CreateBranch(ObjectId objectId, string branchName) { RefUpdate updateRef = db.UpdateRef(branchName); updateRef.SetNewObjectId(objectId); updateRef.Update(); }
public virtual void TestUpdateSmudgedEntries() { git.BranchCreate().SetName("test2").Call(); RefUpdate rup = db.UpdateRef(Constants.HEAD); rup.Link("refs/heads/test2"); FilePath file = new FilePath(db.WorkTree, "Test.txt"); long size = file.Length(); long mTime = file.LastModified() - 5000L; NUnit.Framework.Assert.IsTrue(file.SetLastModified(mTime)); DirCache cache = DirCache.Lock(db.GetIndexFile(), db.FileSystem); DirCacheEntry entry = cache.GetEntry("Test.txt"); NUnit.Framework.Assert.IsNotNull(entry); entry.SetLength(0); entry.LastModified = 0; cache.Write(); NUnit.Framework.Assert.IsTrue(cache.Commit()); cache = DirCache.Read(db.GetIndexFile(), db.FileSystem); entry = cache.GetEntry("Test.txt"); NUnit.Framework.Assert.IsNotNull(entry); NUnit.Framework.Assert.AreEqual(0, entry.Length); NUnit.Framework.Assert.AreEqual(0, entry.LastModified); db.GetIndexFile().SetLastModified(db.GetIndexFile().LastModified() - 5000); NUnit.Framework.Assert.IsNotNull(git.Checkout().SetName("test").Call()); cache = DirCache.Read(db.GetIndexFile(), db.FileSystem); entry = cache.GetEntry("Test.txt"); NUnit.Framework.Assert.IsNotNull(entry); NUnit.Framework.Assert.AreEqual(size, entry.Length); NUnit.Framework.Assert.AreEqual(mTime, entry.LastModified); }
private void Execute(ReceiveCommand cmd) { try { RefUpdate ru = db.UpdateRef(cmd.getRefName()); ru.RefLogIdent = getRefLogIdent(); switch (cmd.getType()) { case ReceiveCommand.Type.DELETE: if (!ObjectId.ZeroId.Equals(cmd.getOldId())) { ru.ExpectedOldObjectId = cmd.getOldId(); } ru.IsForceUpdate = true; Status(cmd, ru.Delete(walk)); break; case ReceiveCommand.Type.CREATE: case ReceiveCommand.Type.UPDATE: case ReceiveCommand.Type.UPDATE_NONFASTFORWARD: ru.IsForceUpdate = isAllowNonFastForwards(); ru.ExpectedOldObjectId = cmd.getOldId(); ru.NewObjectId = cmd.getNewId(); ru.SetRefLogMessage("push", true); Status(cmd, ru.Update(walk)); break; } } catch (IOException err) { cmd.setResult(ReceiveCommand.Result.REJECTED_OTHER_REASON, "lock error: " + err.Message); } }
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 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 TrackingRefUpdate(Repository db, string localName, string remoteName, bool forceUpdate, AnyObjectId nv, string msg) { RemoteName = remoteName; update = db.UpdateRef(localName); update.IsForceUpdate = forceUpdate; update.NewObjectId = nv.Copy(); update.SetRefLogMessage(msg, true); }
public TrackingRefUpdate(Repository db, string localName, string remoteName, bool forceUpdate, AnyObjectId nv, string msg) { if (db == null) throw new System.ArgumentNullException("db"); if (nv == null) throw new System.ArgumentNullException("nv"); RemoteName = remoteName; update = db.UpdateRef(localName); update.IsForceUpdate = forceUpdate; update.NewObjectId = nv.Copy(); update.setRefLogMessage(msg, true); }
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 ' '; } }
private void delete(RefUpdate @ref, RefUpdate.RefUpdateResult expected, bool exists, bool removed) { Assert.AreEqual(exists, db.getRef(@ref.Name) != null); Assert.AreEqual(expected, @ref.Delete()); Assert.AreEqual(!removed, db.getRef(@ref.Name) != null); }
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 void delete(RefUpdate @ref, RefUpdate.RefUpdateResult expected) { delete(@ref, expected, true, true); }