Skip to content

Commit bebfe81

Browse files
committed
[Stash] Add stash API.
1 parent 9d93fba commit bebfe81

12 files changed

+65
-11
lines changed
-965 KB
Binary file not shown.
969 KB
Binary file not shown.

LibGit2Sharp/Core/NativeDllName.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ namespace LibGit2Sharp.Core
22
{
33
internal static class NativeDllName
44
{
5-
public const string Name = "git2-65f6c1c";
5+
public const string Name = "git2-f9589eb";
66
}
77
}

LibGit2Sharp/Core/NativeMethods.cs

+6
Original file line numberDiff line numberDiff line change
@@ -1330,6 +1330,12 @@ internal static extern int git_stash_foreach(
13301330
[DllImport(libgit2)]
13311331
internal static extern int git_stash_drop(RepositorySafeHandle repo, UIntPtr index);
13321332

1333+
[DllImport(libgit2)]
1334+
internal static extern int git_stash_apply(RepositorySafeHandle repo, UIntPtr index, [MarshalAs(UnmanagedType.Bool)] bool reinstate_index);
1335+
1336+
[DllImport(libgit2)]
1337+
internal static extern int git_stash_pop(RepositorySafeHandle repo, UIntPtr index, [MarshalAs(UnmanagedType.Bool)] bool reinstate_index);
1338+
13331339
[DllImport(libgit2)]
13341340
internal static extern int git_status_file(
13351341
out FileStatus statusflags,

LibGit2Sharp/Core/Proxy.cs

+18
Original file line numberDiff line numberDiff line change
@@ -2647,6 +2647,24 @@ public static void git_stash_drop(RepositorySafeHandle repo, int index)
26472647
}
26482648
}
26492649

2650+
public static void git_stash_apply(RepositorySafeHandle repo, int index, bool stage)
2651+
{
2652+
using (ThreadAffinity())
2653+
{
2654+
int res = NativeMethods.git_stash_apply(repo, (UIntPtr)index, stage);
2655+
Ensure.BooleanResult(res);
2656+
}
2657+
}
2658+
2659+
public static void git_stash_pop(RepositorySafeHandle repo, int index, bool stage)
2660+
{
2661+
using (ThreadAffinity())
2662+
{
2663+
int res = NativeMethods.git_stash_pop(repo, (UIntPtr)index, stage);
2664+
Ensure.BooleanResult(res);
2665+
}
2666+
}
2667+
26502668
#endregion
26512669

26522670
#region git_status_

LibGit2Sharp/StashCollection.cs

+30
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,36 @@ public virtual void Remove(int index)
114114
Proxy.git_stash_drop(repo.Handle, index);
115115
}
116116

117+
/// <summary>
118+
/// Apply a single stash to the repository.
119+
/// </summary>
120+
/// <param name="index">The index of the stash to remove (0 being the most recent one).</param>
121+
/// <param name="reinstateIndex">Whether to stage the items or not.</param>
122+
public virtual void Apply(int index, bool reinstateIndex)
123+
{
124+
if (index < 0)
125+
{
126+
throw new ArgumentException("The passed index must be a positive integer.", "index");
127+
}
128+
129+
Proxy.git_stash_apply(repo.Handle, index, reinstateIndex);
130+
}
131+
132+
/// <summary>
133+
/// Applies a stash to the repository and drops it.
134+
/// </summary>
135+
/// <param name="index">The index of the stash to remove (0 being the most recent one).</param>
136+
/// <param name="reinstateIndex">Whether to stage the items or not.</param>
137+
public virtual void Pop(int index, bool reinstateIndex)
138+
{
139+
if (index < 0)
140+
{
141+
throw new ArgumentException("The passed index must be a positive integer.", "index");
142+
}
143+
144+
Proxy.git_stash_pop(repo.Handle, index, reinstateIndex);
145+
}
146+
117147
private string DebuggerDisplay
118148
{
119149
get

LibGit2Sharp/libgit2_hash.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
65f6c1c7eb7beb412e30cacd5cbb2b00e1e975b0
1+
f9589eb6b37cbe0419c59cb6c7f92dbc7145a4ef

nuget.package/build/LibGit2Sharp.props

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<ItemGroup>
4-
<None Include="$(MSBuildThisFileDirectory)\..\..\lib\net40\NativeBinaries\amd64\git2-65f6c1c.dll">
5-
<Link>NativeBinaries\amd64\git2-65f6c1c.dll</Link>
4+
<None Include="$(MSBuildThisFileDirectory)\..\..\lib\net40\NativeBinaries\amd64\git2-f9589eb.dll">
5+
<Link>NativeBinaries\amd64\git2-f9589eb.dll</Link>
66
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
77
</None>
8-
<None Include="$(MSBuildThisFileDirectory)\..\..\lib\net40\NativeBinaries\amd64\git2-65f6c1c.pdb">
9-
<Link>NativeBinaries\amd64\git2-65f6c1c.pdb</Link>
8+
<None Include="$(MSBuildThisFileDirectory)\..\..\lib\net40\NativeBinaries\amd64\git2-f9589eb.pdb">
9+
<Link>NativeBinaries\amd64\git2-f9589eb.pdb</Link>
1010
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
1111
</None>
12-
<None Include="$(MSBuildThisFileDirectory)\..\..\lib\net40\NativeBinaries\x86\git2-65f6c1c.dll">
13-
<Link>NativeBinaries\x86\git2-65f6c1c.dll</Link>
12+
<None Include="$(MSBuildThisFileDirectory)\..\..\lib\net40\NativeBinaries\x86\git2-f9589eb.dll">
13+
<Link>NativeBinaries\x86\git2-f9589eb.dll</Link>
1414
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
1515
</None>
16-
<None Include="$(MSBuildThisFileDirectory)\..\..\lib\net40\NativeBinaries\x86\git2-65f6c1c.pdb">
17-
<Link>NativeBinaries\x86\git2-65f6c1c.pdb</Link>
16+
<None Include="$(MSBuildThisFileDirectory)\..\..\lib\net40\NativeBinaries\x86\git2-f9589eb.pdb">
17+
<Link>NativeBinaries\x86\git2-f9589eb.pdb</Link>
1818
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
1919
</None>
2020
</ItemGroup>

0 commit comments

Comments
 (0)