using System.Globalization; using System.Linq; namespace LibGit2Sharp { /// /// A Stash /// A stash is a snapshot of the dirty state of the working directory (i.e. the modified tracked files and staged changes) /// public class Stash : ReferenceWrapper { /// /// Needed for mocking purposes. /// protected Stash() { } internal Stash(Repository repo, ObjectId targetId, int index) : base(repo, new DirectReference(string.Format(CultureInfo.InvariantCulture, "stash@{{{0}}}", index), repo, targetId), r => r.CanonicalName) { } /// /// Gets the that contains to the captured content of the worktree when the /// stash was created. /// public virtual Commit WorkTree { get { return TargetObject; } } /// /// Gets the base (i.e. the HEAD when the stash was /// created). /// public virtual Commit Base { get { return TargetObject.Parents.First(); } } /// /// Gets the that contains the captured content of the index when the stash was /// created. /// public virtual Commit Index { get { return GetParentAtOrDefault(1); } } /// /// Gets the that contains the list of either the untracked files, the ignored files, or both, /// depending on the options passed when the stash was created. /// public virtual Commit Untracked { get { return GetParentAtOrDefault(2); } } private Commit GetParentAtOrDefault(int parentIndex) { return TargetObject.Parents.ElementAtOrDefault(parentIndex); } /// /// Gets the message associated to this . /// public virtual string Message { get { return WorkTree.Message; } } /// /// Returns "stash@{i}", where i is the index of this . /// protected override string Shorten() { return CanonicalName; } } }