Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Introduce Stash.Apply and Stash.Drop
  • Loading branch information
Therzok committed Apr 6, 2015
commit ec7a71f42decc96ba2d21213faa7b16cd0410796
14 changes: 14 additions & 0 deletions LibGit2Sharp/Core/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,20 @@ internal static extern int git_stash_foreach(
[DllImport(libgit2)]
internal static extern int git_stash_drop(RepositorySafeHandle repo, UIntPtr index);

[DllImport(libgit2)]
internal static extern int git_stash_apply(
RepositorySafeHandle repo,
UIntPtr index,
ref GitCheckoutOpts opts,
StashApplyModifiers flags);

[DllImport(libgit2)]
internal static extern int git_stash_pop(
RepositorySafeHandle repo,
UIntPtr index,
ref GitCheckoutOpts opts,
StashApplyModifiers flags);

[DllImport(libgit2)]
internal static extern int git_status_file(
out FileStatus statusflags,
Expand Down
26 changes: 26 additions & 0 deletions LibGit2Sharp/Core/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2723,6 +2723,32 @@ public static void git_stash_drop(RepositorySafeHandle repo, int index)
}
}

public static void git_stash_apply(
RepositorySafeHandle repo,
int index,
ref GitCheckoutOpts opts,
StashApplyModifiers flags)
{
using (ThreadAffinity())
{
int res = NativeMethods.git_stash_apply(repo, (UIntPtr)index, ref opts, flags);
Ensure.ZeroResult(res);
}
}

public static void git_stash_pop(
RepositorySafeHandle repo,
int index,
ref GitCheckoutOpts opts,
StashApplyModifiers flags)
{
using (ThreadAffinity())
{
int res = NativeMethods.git_stash_pop(repo, (UIntPtr)index, ref opts, flags);
Ensure.ZeroResult(res);
}
}

#endregion

#region git_status_
Expand Down
30 changes: 30 additions & 0 deletions LibGit2Sharp/StashCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,36 @@ public virtual void Remove(int index)
Proxy.git_stash_drop(repo.Handle, index);
}

/// <summary>
/// Applies a single stashed state from the stash list
/// </summary>
/// <param name="index">the index of the stash to remove (0 being the most recent one).</param>
/// <param name="options">the options to use for checking out the stash.</param>
/// <param name="flags">the flags to use for applying the changes.</param>
public virtual void Apply(int index, CheckoutOptions options = null, StashApplyModifiers flags = StashApplyModifiers.Default)
{
using (GitCheckoutOptsWrapper checkoutOptionsWrapper = new GitCheckoutOptsWrapper(options))
{
var opts = checkoutOptionsWrapper.Options;
Proxy.git_stash_apply(repo.Handle, index, ref opts, flags);
}
}

/// <summary>
/// Pops a single stashed state from the stash list
/// </summary>
/// <param name="index">the index of the stash to remove (0 being the most recent one).</param>
/// <param name="options">the options to use for checking out the stash.</param>
/// <param name="flags">the flags to use for applying the changes.</param>
public virtual void Pop(int index, CheckoutOptions options = null, StashApplyModifiers flags = StashApplyModifiers.Default)
{
using (GitCheckoutOptsWrapper checkoutOptionsWrapper = new GitCheckoutOptsWrapper(options))
{
var opts = checkoutOptionsWrapper.Options;
Proxy.git_stash_pop(repo.Handle, index, ref opts, flags);
}
}

private string DebuggerDisplay
{
get
Expand Down
19 changes: 19 additions & 0 deletions LibGit2Sharp/StashModifiers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,23 @@ public enum StashModifiers
/// </summary>
IncludeIgnored = (1 << 2),
}

///<summary>
/// Options controlling Stash applying behavior.
///</summary>
[Flags]
public enum StashApplyModifiers
{
/// <summary>
/// Default. Reinstante working directory stashed
/// changes.
/// </summary>
Default = 0,

/// <summary>
/// Reinstate both index and working directory stashed
/// changes.
/// </summary>
ReinstateIndex = (1 << 0),
}
}