public static string sha1(this ReflogEntry reflog) { if (reflog.notNull()) { return(reflog.GetNewId().Name); } return(null); }
public virtual void RefLogIncludesCommitMessage() { PersonIdent who = new PersonIdent("user", "*****@*****.**"); DeleteTrashFile("file.txt"); RevCommit stashed = git.StashCreate().SetPerson(who).Call(); NUnit.Framework.Assert.IsNotNull(stashed); NUnit.Framework.Assert.AreEqual("content", Read(committedFile)); ValidateStashedCommit(stashed); ReflogReader reader = new ReflogReader(git.GetRepository(), Constants.R_STASH); ReflogEntry entry = reader.GetLastEntry(); NUnit.Framework.Assert.IsNotNull(entry); NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, entry.GetOldId()); NUnit.Framework.Assert.AreEqual(stashed, entry.GetNewId()); NUnit.Framework.Assert.AreEqual(who, entry.GetWho()); NUnit.Framework.Assert.AreEqual(stashed.GetFullMessage(), entry.GetComment()); }
/// <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); } }