public virtual void DropFirstStashedCommit() { Write(committedFile, "content2"); Ref stashRef = git.GetRepository().GetRef(Constants.R_STASH); NUnit.Framework.Assert.IsNull(stashRef); RevCommit firstStash = git.StashCreate().Call(); NUnit.Framework.Assert.IsNotNull(firstStash); stashRef = git.GetRepository().GetRef(Constants.R_STASH); NUnit.Framework.Assert.IsNotNull(stashRef); NUnit.Framework.Assert.AreEqual(firstStash, git.GetRepository().GetRef(Constants. R_STASH).GetObjectId()); Write(committedFile, "content3"); RevCommit secondStash = git.StashCreate().Call(); NUnit.Framework.Assert.IsNotNull(secondStash); stashRef = git.GetRepository().GetRef(Constants.R_STASH); NUnit.Framework.Assert.IsNotNull(stashRef); NUnit.Framework.Assert.AreEqual(secondStash, git.GetRepository().GetRef(Constants .R_STASH).GetObjectId()); NUnit.Framework.Assert.AreEqual(firstStash, git.StashDrop().Call()); stashRef = git.GetRepository().GetRef(Constants.R_STASH); NUnit.Framework.Assert.IsNotNull(stashRef); NUnit.Framework.Assert.AreEqual(firstStash, stashRef.GetObjectId()); ReflogReader reader = new ReflogReader(git.GetRepository(), Constants.R_STASH); IList <ReflogEntry> entries = reader.GetReverseEntries(); NUnit.Framework.Assert.AreEqual(1, entries.Count); NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, entries[0].GetOldId()); NUnit.Framework.Assert.AreEqual(firstStash, entries[0].GetNewId()); NUnit.Framework.Assert.IsTrue(entries[0].GetComment().Length > 0); }
public virtual void DropAll() { Write(committedFile, "content2"); Ref stashRef = git.GetRepository().GetRef(Constants.R_STASH); NUnit.Framework.Assert.IsNull(stashRef); RevCommit firstStash = git.StashCreate().Call(); NUnit.Framework.Assert.IsNotNull(firstStash); stashRef = git.GetRepository().GetRef(Constants.R_STASH); NUnit.Framework.Assert.IsNotNull(stashRef); NUnit.Framework.Assert.AreEqual(firstStash, git.GetRepository().GetRef(Constants. R_STASH).GetObjectId()); Write(committedFile, "content3"); RevCommit secondStash = git.StashCreate().Call(); NUnit.Framework.Assert.IsNotNull(secondStash); stashRef = git.GetRepository().GetRef(Constants.R_STASH); NUnit.Framework.Assert.IsNotNull(stashRef); NUnit.Framework.Assert.AreEqual(secondStash, git.GetRepository().GetRef(Constants .R_STASH).GetObjectId()); NUnit.Framework.Assert.IsNull(git.StashDrop().SetAll(true).Call()); NUnit.Framework.Assert.IsNull(git.GetRepository().GetRef(Constants.R_STASH)); ReflogReader reader = new ReflogReader(git.GetRepository(), Constants.R_STASH); NUnit.Framework.Assert.IsTrue(reader.GetReverseEntries().IsEmpty()); }
/// <summary>Run the reflog command</summary> /// <exception cref="NGit.Api.Errors.GitAPIException">NGit.Api.Errors.GitAPIException /// </exception> /// <exception cref="NGit.Api.Errors.InvalidRefNameException">NGit.Api.Errors.InvalidRefNameException /// </exception> public override ICollection <ReflogEntry> Call() { CheckCallable(); try { ReflogReader reader = new ReflogReader(repo, @ref); return(reader.GetReverseEntries()); } catch (IOException e) { throw new InvalidRefNameException(MessageFormat.Format(JGitText.Get().cannotRead, @ref), e); } }
public virtual void DropSingleStashedCommit() { Write(committedFile, "content2"); Ref stashRef = git.GetRepository().GetRef(Constants.R_STASH); NUnit.Framework.Assert.IsNull(stashRef); RevCommit stashed = git.StashCreate().Call(); NUnit.Framework.Assert.IsNotNull(stashed); stashRef = git.GetRepository().GetRef(Constants.R_STASH); NUnit.Framework.Assert.AreEqual(stashed, git.GetRepository().GetRef(Constants.R_STASH ).GetObjectId()); NUnit.Framework.Assert.IsNull(git.StashDrop().Call()); stashRef = git.GetRepository().GetRef(Constants.R_STASH); NUnit.Framework.Assert.IsNull(stashRef); ReflogReader reader = new ReflogReader(git.GetRepository(), Constants.R_STASH); NUnit.Framework.Assert.IsTrue(reader.GetReverseEntries().IsEmpty()); }
/// <summary> /// Drop the configured entry from the stash reflog and return value of the /// stash reference after the drop occurs /// </summary> /// <returns>commit id of stash reference or null if no more stashed changes</returns> /// <exception cref="NGit.Api.Errors.GitAPIException">NGit.Api.Errors.GitAPIException /// </exception> public override ObjectId Call() { CheckCallable(); Ref stashRef = GetRef(); if (stashRef == null) { return(null); } if (all) { DeleteRef(stashRef); return(null); } ReflogReader reader = new ReflogReader(repo, Constants.R_STASH); IList <ReflogEntry> entries; try { entries = reader.GetReverseEntries(); } catch (IOException e) { throw new JGitInternalException(JGitText.Get().stashDropFailed, e); } if (stashRefEntry >= entries.Count) { throw new JGitInternalException(JGitText.Get().stashDropMissingReflog); } if (entries.Count == 1) { DeleteRef(stashRef); return(null); } ReflogWriter writer = new ReflogWriter(repo, true); string stashLockRef = ReflogWriter.RefLockFor(Constants.R_STASH); FilePath stashLockFile = writer.LogFor(stashLockRef); FilePath stashFile = writer.LogFor(Constants.R_STASH); if (stashLockFile.Exists()) { throw new JGitInternalException(JGitText.Get().stashDropFailed, new LockFailedException (stashFile)); } entries.Remove(stashRefEntry); ObjectId entryId = ObjectId.ZeroId; try { for (int i = entries.Count - 1; i >= 0; i--) { ReflogEntry entry = entries[i]; writer.Log(stashLockRef, entryId, entry.GetNewId(), entry.GetWho(), entry.GetComment ()); entryId = entry.GetNewId(); } if (!stashLockFile.RenameTo(stashFile)) { FileUtils.Delete(stashFile); if (!stashLockFile.RenameTo(stashFile)) { throw new JGitInternalException(MessageFormat.Format(JGitText.Get().couldNotWriteFile , stashLockFile.GetPath(), stashFile.GetPath())); } } } catch (IOException e) { throw new JGitInternalException(JGitText.Get().stashDropFailed, e); } UpdateRef(stashRef, entryId); try { Ref newStashRef = repo.GetRef(Constants.R_STASH); return(newStashRef != null?newStashRef.GetObjectId() : null); } catch (IOException e) { throw new InvalidRefNameException(MessageFormat.Format(JGitText.Get().cannotRead, Constants.R_STASH), e); } }