public virtual void TestDeleteLooseAndItsDirectory() { ObjectId pid = db.Resolve("refs/heads/c^"); RefUpdate updateRef = db.UpdateRef("refs/heads/z/c"); updateRef.SetNewObjectId(pid); updateRef.SetForceUpdate(true); updateRef.SetRefLogMessage("new test ref", false); RefUpdate.Result update = updateRef.Update(); NUnit.Framework.Assert.AreEqual(RefUpdate.Result.NEW, update); // internal NUnit.Framework.Assert.IsTrue(new FilePath(db.Directory, Constants.R_HEADS + "z") .Exists()); NUnit.Framework.Assert.IsTrue(new FilePath(db.Directory, "logs/refs/heads/z").Exists ()); // The real test here RefUpdate updateRef2 = db.UpdateRef("refs/heads/z/c"); updateRef2.SetForceUpdate(true); RefUpdate.Result delete = updateRef2.Delete(); NUnit.Framework.Assert.AreEqual(RefUpdate.Result.FORCED, delete); NUnit.Framework.Assert.IsNull(db.Resolve("refs/heads/z/c")); NUnit.Framework.Assert.IsFalse(new FilePath(db.Directory, Constants.R_HEADS + "z" ).Exists()); NUnit.Framework.Assert.IsFalse(new FilePath(db.Directory, "logs/refs/heads/z").Exists ()); }
public virtual void TestUpdateRefDetachedUnbornHead() { ObjectId ppid = db.Resolve("refs/heads/master^"); WriteSymref("HEAD", "refs/heads/unborn"); RefUpdate updateRef = db.UpdateRef("HEAD", true); updateRef.SetForceUpdate(true); updateRef.SetNewObjectId(ppid); RefUpdate.Result update = updateRef.Update(); NUnit.Framework.Assert.AreEqual(RefUpdate.Result.NEW, update); NUnit.Framework.Assert.AreEqual(ppid, db.Resolve("HEAD")); Ref @ref = db.GetRef("HEAD"); NUnit.Framework.Assert.AreEqual("HEAD", @ref.GetName()); NUnit.Framework.Assert.IsTrue([email protected](), "is detached"); // the branch HEAD referred to is left untouched NUnit.Framework.Assert.IsNull(db.Resolve("refs/heads/unborn")); ReflogReader reflogReader = new ReflogReader(db, "HEAD"); ReflogEntry e = reflogReader.GetReverseEntries()[0]; NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, e.GetOldId()); NUnit.Framework.Assert.AreEqual(ppid, e.GetNewId()); NUnit.Framework.Assert.AreEqual("GIT_COMMITTER_EMAIL", e.GetWho().GetEmailAddress ()); NUnit.Framework.Assert.AreEqual("GIT_COMMITTER_NAME", e.GetWho().GetName()); NUnit.Framework.Assert.AreEqual(1250379778000L, e.GetWho().GetWhen().GetTime()); }
/// <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(); } }
public virtual void TestRenameCurrentBranch() { ObjectId rb = db.Resolve("refs/heads/b"); WriteSymref(Constants.HEAD, "refs/heads/b"); ObjectId oldHead = db.Resolve(Constants.HEAD); NUnit.Framework.Assert.AreEqual(oldHead, rb, "internal test condition, b == HEAD" ); WriteReflog(db, rb, "Just a message", "refs/heads/b"); NUnit.Framework.Assert.IsTrue(new FilePath(db.Directory, "logs/refs/heads/b").Exists (), "log on old branch"); RefRename renameRef = db.RenameRef("refs/heads/b", "refs/heads/new/name"); RefUpdate.Result result = renameRef.Rename(); NUnit.Framework.Assert.AreEqual(RefUpdate.Result.RENAMED, result); NUnit.Framework.Assert.AreEqual(rb, db.Resolve("refs/heads/new/name")); NUnit.Framework.Assert.IsNull(db.Resolve("refs/heads/b")); NUnit.Framework.Assert.AreEqual("Branch: renamed b to new/name", db.GetReflogReader ("new/name").GetLastEntry().GetComment()); NUnit.Framework.Assert.IsFalse(new FilePath(db.Directory, "logs/refs/heads/b").Exists ()); NUnit.Framework.Assert.AreEqual(rb, db.Resolve(Constants.HEAD)); NUnit.Framework.Assert.AreEqual(2, db.GetReflogReader("new/name").GetReverseEntries ().Count); NUnit.Framework.Assert.AreEqual("Branch: renamed b to new/name", db.GetReflogReader ("new/name").GetReverseEntries()[0].GetComment()); NUnit.Framework.Assert.AreEqual("Just a message", db.GetReflogReader("new/name"). GetReverseEntries()[1].GetComment()); }
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 virtual void TestNoCacheObjectIdSubclass() { string newRef = "refs/heads/abc"; RefUpdate ru = UpdateRef(newRef); RefUpdateTest.SubclassedId newid = new RefUpdateTest.SubclassedId(ru.GetNewObjectId ()); ru.SetNewObjectId(newid); RefUpdate.Result update = ru.Update(); NUnit.Framework.Assert.AreEqual(RefUpdate.Result.NEW, update); Ref r = db.GetAllRefs().Get(newRef); NUnit.Framework.Assert.IsNotNull(r); NUnit.Framework.Assert.AreEqual(newRef, r.GetName()); NUnit.Framework.Assert.IsNotNull(r.GetObjectId()); NUnit.Framework.Assert.AreNotSame(newid, r.GetObjectId()); NUnit.Framework.Assert.AreSame(typeof(ObjectId), r.GetObjectId().GetType()); NUnit.Framework.Assert.AreEqual(newid, r.GetObjectId()); IList <ReflogEntry> reverseEntries1 = db.GetReflogReader("refs/heads/abc").GetReverseEntries (); ReflogEntry entry1 = reverseEntries1[0]; NUnit.Framework.Assert.AreEqual(1, reverseEntries1.Count); NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, entry1.GetOldId()); NUnit.Framework.Assert.AreEqual(r.GetObjectId(), entry1.GetNewId()); NUnit.Framework.Assert.AreEqual(new PersonIdent(db).ToString(), entry1.GetWho().ToString ()); NUnit.Framework.Assert.AreEqual(string.Empty, entry1.GetComment()); IList <ReflogEntry> reverseEntries2 = db.GetReflogReader("HEAD").GetReverseEntries (); NUnit.Framework.Assert.AreEqual(0, reverseEntries2.Count); }
/// <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(); } }
/// <summary>Delete the ref.</summary> /// <remarks>Delete the ref.</remarks> /// <param name="walk"> /// a RevWalk instance this delete command can borrow to perform /// the merge test. The walk will be reset to perform the test. /// </param> /// <returns>the result status of the delete.</returns> /// <exception cref="System.IO.IOException">System.IO.IOException</exception> public virtual RefUpdate.Result Delete(RevWalk walk) { string myName = GetRef().GetLeaf().GetName(); if (myName.StartsWith(Constants.R_HEADS)) { Ref head = GetRefDatabase().GetRef(Constants.HEAD); while (head.IsSymbolic()) { head = head.GetTarget(); if (myName.Equals(head.GetName())) { return(result = RefUpdate.Result.REJECTED_CURRENT_BRANCH); } } } try { return(result = UpdateImpl(walk, new _Store_540(this))); } catch (IOException x) { result = RefUpdate.Result.IO_FAILURE; throw; } }
private string ToResultString(RefUpdate.Result status) { switch (status) { case RefUpdate.Result.FORCED: { return("forced-update"); } case RefUpdate.Result.FAST_FORWARD: { return("fast forward"); } case RefUpdate.Result.NEW: { return("created"); } default: { return(null); break; } } }
/// <param name="message"></param> /// <param name="ref"></param> /// <param name="rc"></param> public ConcurrentRefUpdateException(string message, Ref @ref, RefUpdate.Result rc ) : base((rc == null) ? message : message + ". " + MessageFormat.Format(JGitText .Get().refUpdateReturnCodeWas, rc)) { this.rc = rc; this.@ref = @ref; }
/// <exception cref="System.IO.IOException"></exception> protected internal override RefUpdate.Result DoUpdate(RefUpdate.Result status) { WriteConfig wc = database.GetRepository().GetConfig().Get(WriteConfig.KEY); Lock.SetFSync(wc.GetFSyncRefFiles()); Lock.SetNeedStatInformation(true); Lock.Write(GetNewObjectId()); string msg = GetRefLogMessage(); if (msg != null) { if (IsRefLogIncludingResult()) { string strResult = ToResultString(status); if (strResult != null) { if (msg.Length > 0) { msg = msg + ": " + strResult; } else { msg = strResult; } } } database.Log(this, msg, true); } if (!Lock.Commit()) { return(RefUpdate.Result.LOCK_FAILURE); } database.Stored(this, Lock.GetCommitSnapshot()); return(status); }
/// <param name="message"></param> /// <param name="ref"></param> /// <param name="rc"></param> /// <param name="cause"></param> public ConcurrentRefUpdateException(string message, Ref @ref, RefUpdate.Result rc , Exception cause) : base((rc == null) ? message : message + ". " + MessageFormat .Format(JGitText.Get().refUpdateReturnCodeWas, rc), cause) { this.rc = rc; this.@ref = @ref; }
/// <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())); }
/// <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 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()); }
/// <exception cref="System.IO.IOException"></exception> /// <exception cref="NGit.Api.Errors.JGitInternalException"></exception> private RevCommit TryFastForward(string headName, RevCommit oldCommit, RevCommit newCommit) { bool tryRebase = false; foreach (RevCommit parentCommit in newCommit.Parents) { if (parentCommit.Equals(oldCommit)) { tryRebase = true; } } if (!tryRebase) { return(null); } CheckoutCommand co = new CheckoutCommand(repo); try { co.SetName(newCommit.Name).Call(); if (headName.StartsWith(Constants.R_HEADS)) { RefUpdate rup = repo.UpdateRef(headName); rup.SetExpectedOldObjectId(oldCommit); rup.SetNewObjectId(newCommit); rup.SetRefLogMessage("Fast-foward from " + oldCommit.Name + " to " + newCommit.Name , false); RefUpdate.Result res = rup.Update(walk); switch (res) { case RefUpdate.Result.FAST_FORWARD: case RefUpdate.Result.NO_CHANGE: case RefUpdate.Result.FORCED: { break; } default: { throw new IOException("Could not fast-forward"); } } } return(newCommit); } catch (RefAlreadyExistsException e) { throw new JGitInternalException(e.Message, e); } catch (RefNotFoundException e) { throw new JGitInternalException(e.Message, e); } catch (InvalidRefNameException e) { throw new JGitInternalException(e.Message, e); } }
/// <exception cref="System.IO.IOException"></exception> internal override RefUpdate.Result Execute(RefUpdate.Result status) { if (status == RefUpdate.Result.NO_CHANGE) { return(status); } return(this._enclosing.DoUpdate(status)); }
/// <exception cref="System.IO.IOException"></exception> protected internal override RefUpdate.Result DoDelete(RefUpdate.Result status) { if (GetRef().GetLeaf().GetStorage() != RefStorage.NEW) { database.Delete(this); } return(status); }
public virtual void TestUpdateRefNoChange() { ObjectId pid = db.Resolve("refs/heads/master"); RefUpdate updateRef = db.UpdateRef("refs/heads/master"); updateRef.SetNewObjectId(pid); RefUpdate.Result update = updateRef.Update(); NUnit.Framework.Assert.AreEqual(RefUpdate.Result.NO_CHANGE, update); NUnit.Framework.Assert.AreEqual(pid, db.Resolve("refs/heads/master")); }
/// <exception cref="System.IO.IOException"></exception> public virtual 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.GetReflogReader(fromName).GetReverseEntries (); IList <ReflogReader.Entry> oldHeadLog = oldHeadId != null?db.GetReflogReader(Constants .HEAD).GetReverseEntries() : null; NUnit.Framework.Assert.IsTrue(new FilePath(db.Directory, "logs/" + fromName).Exists (), "internal check, we have a log"); // "someone" has branch X locked LockFile lockFile = new LockFile(new FilePath(db.Directory, toLock), db.FileSystem ); try { NUnit.Framework.Assert.IsTrue(lockFile.Lock()); // Now this is our test RefRename renameRef = db.RenameRef(fromName, toName); RefUpdate.Result result = renameRef.Rename(); NUnit.Framework.Assert.AreEqual(RefUpdate.Result.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"); NUnit.Framework.Assert.AreEqual(oldHeadId, db.Resolve(Constants.HEAD)); NUnit.Framework.Assert.AreEqual(oldfromId, db.Resolve(fromName)); NUnit.Framework.Assert.IsNull(db.Resolve(toName)); NUnit.Framework.Assert.AreEqual(oldFromLog.ToString(), db.GetReflogReader(fromName ).GetReverseEntries().ToString()); if (oldHeadId != null) { NUnit.Framework.Assert.AreEqual(oldHeadLog.ToString(), db.GetReflogReader(Constants .HEAD).GetReverseEntries().ToString()); } } finally { lockFile.Unlock(); } }
public virtual void TestUpdateRefLockFailureWrongOldValue() { ObjectId pid = db.Resolve("refs/heads/master"); RefUpdate updateRef = db.UpdateRef("refs/heads/master"); updateRef.SetNewObjectId(pid); updateRef.SetExpectedOldObjectId(db.Resolve("refs/heads/master^")); RefUpdate.Result update = updateRef.Update(); NUnit.Framework.Assert.AreEqual(RefUpdate.Result.LOCK_FAILURE, update); NUnit.Framework.Assert.AreEqual(pid, db.Resolve("refs/heads/master")); }
public virtual void TestNewNamespaceConflictWithPackedPrefixOfExisting() { string newRef = "refs/heads/prefix"; RefUpdate ru = UpdateRef(newRef); RefUpdate.Result update = ru.Update(); NUnit.Framework.Assert.AreEqual(RefUpdate.Result.LOCK_FAILURE, update); NUnit.Framework.Assert.IsNull(db.GetReflogReader("refs/heads/prefix")); NUnit.Framework.Assert.AreEqual(0, db.GetReflogReader("HEAD").GetReverseEntries() .Count); }
public virtual void TestDeleteLoosePackedRejected() { ObjectId pid = db.Resolve("refs/heads/c^"); ObjectId oldpid = db.Resolve("refs/heads/c"); RefUpdate updateRef = db.UpdateRef("refs/heads/c"); updateRef.SetNewObjectId(pid); RefUpdate.Result update = updateRef.Update(); NUnit.Framework.Assert.AreEqual(RefUpdate.Result.REJECTED, update); NUnit.Framework.Assert.AreEqual(oldpid, db.Resolve("refs/heads/c")); }
public virtual void TestReadLooseRef() { RefUpdate updateRef = db.UpdateRef("ref/heads/new"); updateRef.SetNewObjectId(db.Resolve("refs/heads/master")); RefUpdate.Result update = updateRef.Update(); NUnit.Framework.Assert.AreEqual(RefUpdate.Result.NEW, update); Ref @ref = db.GetRef("ref/heads/new"); NUnit.Framework.Assert.AreEqual(RefStorage.LOOSE, @ref.GetStorage()); }
/// <returns>the result of the new ref update</returns> /// <exception cref="System.IO.IOException">System.IO.IOException</exception> public virtual RefUpdate.Result Rename() { try { result = DoRename(); return(result); } catch (IOException err) { result = RefUpdate.Result.IO_FAILURE; throw; } }
/// <summary>Gracefully update the ref to the new value.</summary> /// <remarks> /// Gracefully update the ref to the new value. /// <p> /// Merge test will be performed according to /// <see cref="IsForceUpdate()">IsForceUpdate()</see> /// . /// </remarks> /// <param name="walk"> /// a RevWalk instance this update command can borrow to perform /// the merge test. The walk will be reset to perform the test. /// </param> /// <returns>the result status of the update.</returns> /// <exception cref="System.IO.IOException">an unexpected IO error occurred while writing changes. /// </exception> public virtual RefUpdate.Result Update(RevWalk walk) { RequireCanDoUpdate(); try { return(result = UpdateImpl(walk, new _Store_484(this))); } catch (IOException x) { result = RefUpdate.Result.IO_FAILURE; throw; } }
public virtual void TestReadSimplePackedRefSameRepo() { Ref @ref = db.GetRef("refs/heads/master"); ObjectId pid = db.Resolve("refs/heads/master^"); NUnit.Framework.Assert.AreEqual(RefStorage.PACKED, @ref.GetStorage()); RefUpdate updateRef = db.UpdateRef("refs/heads/master"); updateRef.SetNewObjectId(pid); updateRef.SetForceUpdate(true); RefUpdate.Result update = updateRef.Update(); NUnit.Framework.Assert.AreEqual(RefUpdate.Result.FORCED, update); @ref = db.GetRef("refs/heads/master"); NUnit.Framework.Assert.AreEqual(RefStorage.LOOSE, @ref.GetStorage()); }
private void DeleteRef(Ref stashRef) { try { RefUpdate.Result result = CreateRefUpdate(stashRef).Delete(); if (RefUpdate.Result.FORCED != result) { throw new JGitInternalException(MessageFormat.Format(JGitText.Get().stashDropDeleteRefFailed , result)); } } catch (IOException e) { throw new JGitInternalException(JGitText.Get().stashDropFailed, e); } }
/// <summary>Replace this reference with a symbolic reference to another reference.</summary> /// <remarks> /// Replace this reference with a symbolic reference to another reference. /// <p> /// This exact reference (not its traversed leaf) is replaced with a symbolic /// reference to the requested name. /// </remarks> /// <param name="target"> /// name of the new target for this reference. The new target name /// must be absolute, so it must begin with /// <code>refs/</code> /// . /// </param> /// <returns> /// /// <see cref="Result.NEW">Result.NEW</see> /// or /// <see cref="Result.FORCED">Result.FORCED</see> /// on success. /// </returns> /// <exception cref="System.IO.IOException">System.IO.IOException</exception> public virtual RefUpdate.Result Link(string target) { if (!target.StartsWith(Constants.R_REFS)) { throw new ArgumentException(MessageFormat.Format(JGitText.Get().illegalArgumentNotA , Constants.R_REFS)); } if (GetRefDatabase().IsNameConflicting(GetName())) { return(RefUpdate.Result.LOCK_FAILURE); } try { if (!TryLock(false)) { return(RefUpdate.Result.LOCK_FAILURE); } Ref old = GetRefDatabase().GetRef(GetName()); if (old != null && old.IsSymbolic()) { Ref dst = old.GetTarget(); if (target.Equals(dst.GetName())) { return(result = RefUpdate.Result.NO_CHANGE); } } if (old != null && old.GetObjectId() != null) { SetOldObjectId(old.GetObjectId()); } Ref dst_1 = GetRefDatabase().GetRef(target); if (dst_1 != null && dst_1.GetObjectId() != null) { SetNewObjectId(dst_1.GetObjectId()); } return(result = DoLink(target)); } catch (IOException x) { result = RefUpdate.Result.IO_FAILURE; throw; } finally { Unlock(); } }
/// <summary>Set the result of this command.</summary> /// <remarks>Set the result of this command.</remarks> /// <param name="r">the new result code for this command.</param> public virtual void SetResult(RefUpdate.Result r) { switch (r) { case RefUpdate.Result.NOT_ATTEMPTED: { SetResult(ReceiveCommand.Result.NOT_ATTEMPTED); break; } case RefUpdate.Result.LOCK_FAILURE: case RefUpdate.Result.IO_FAILURE: { SetResult(ReceiveCommand.Result.LOCK_FAILURE); break; } case RefUpdate.Result.NO_CHANGE: case RefUpdate.Result.NEW: case RefUpdate.Result.FORCED: case RefUpdate.Result.FAST_FORWARD: { SetResult(ReceiveCommand.Result.OK); break; } case RefUpdate.Result.REJECTED: { SetResult(ReceiveCommand.Result.REJECTED_NONFASTFORWARD); break; } case RefUpdate.Result.REJECTED_CURRENT_BRANCH: { SetResult(ReceiveCommand.Result.REJECTED_CURRENT_BRANCH); break; } default: { SetResult(ReceiveCommand.Result.REJECTED_OTHER_REASON, r.ToString()); break; break; } } }
internal virtual void SetResult(RefUpdate.Result result) { this.result = result; }
/// <summary>Replace this reference with a symbolic reference to another reference.</summary> /// <remarks> /// Replace this reference with a symbolic reference to another reference. /// <p> /// This exact reference (not its traversed leaf) is replaced with a symbolic /// reference to the requested name. /// </remarks> /// <param name="target"> /// name of the new target for this reference. The new target name /// must be absolute, so it must begin with /// <code>refs/</code> /// . /// </param> /// <returns> /// /// <see cref="Result.NEW">Result.NEW</see> /// or /// <see cref="Result.FORCED">Result.FORCED</see> /// on success. /// </returns> /// <exception cref="System.IO.IOException">System.IO.IOException</exception> public virtual RefUpdate.Result Link(string target) { if (!target.StartsWith(Constants.R_REFS)) { throw new ArgumentException(MessageFormat.Format(JGitText.Get().illegalArgumentNotA , Constants.R_REFS)); } if (GetRefDatabase().IsNameConflicting(GetName())) { return RefUpdate.Result.LOCK_FAILURE; } try { if (!TryLock(false)) { return RefUpdate.Result.LOCK_FAILURE; } Ref old = GetRefDatabase().GetRef(GetName()); if (old != null && old.IsSymbolic()) { Ref dst = old.GetTarget(); if (target.Equals(dst.GetName())) { return result = RefUpdate.Result.NO_CHANGE; } } if (old != null && old.GetObjectId() != null) { SetOldObjectId(old.GetObjectId()); } Ref dst_1 = GetRefDatabase().GetRef(target); if (dst_1 != null && dst_1.GetObjectId() != null) { SetNewObjectId(dst_1.GetObjectId()); } return result = DoLink(target); } catch (IOException x) { result = RefUpdate.Result.IO_FAILURE; throw; } finally { Unlock(); } }
/// <summary>Delete the ref.</summary> /// <remarks>Delete the ref.</remarks> /// <param name="walk"> /// a RevWalk instance this delete command can borrow to perform /// the merge test. The walk will be reset to perform the test. /// </param> /// <returns>the result status of the delete.</returns> /// <exception cref="System.IO.IOException">System.IO.IOException</exception> public virtual RefUpdate.Result Delete(RevWalk walk) { string myName = GetRef().GetLeaf().GetName(); if (myName.StartsWith(Constants.R_HEADS)) { Ref head = GetRefDatabase().GetRef(Constants.HEAD); while (head.IsSymbolic()) { head = head.GetTarget(); if (myName.Equals(head.GetName())) { return result = RefUpdate.Result.REJECTED_CURRENT_BRANCH; } } } try { return result = UpdateImpl(walk, new _Store_540(this)); } catch (IOException x) { result = RefUpdate.Result.IO_FAILURE; throw; } }
/// <summary>Gracefully update the ref to the new value.</summary> /// <remarks> /// Gracefully update the ref to the new value. /// <p> /// Merge test will be performed according to /// <see cref="IsForceUpdate()">IsForceUpdate()</see> /// . /// </remarks> /// <param name="walk"> /// a RevWalk instance this update command can borrow to perform /// the merge test. The walk will be reset to perform the test. /// </param> /// <returns>the result status of the update.</returns> /// <exception cref="System.IO.IOException">an unexpected IO error occurred while writing changes. /// </exception> public virtual RefUpdate.Result Update(RevWalk walk) { RequireCanDoUpdate(); try { return result = UpdateImpl(walk, new _Store_484(this)); } catch (IOException x) { result = RefUpdate.Result.IO_FAILURE; throw; } }
/// <returns>the result of the new ref update</returns> /// <exception cref="System.IO.IOException">System.IO.IOException</exception> public virtual RefUpdate.Result Rename() { try { result = DoRename(); return result; } catch (IOException err) { result = RefUpdate.Result.IO_FAILURE; throw; } }