Skip to content

Commit f95748a

Browse files
committed
Update mdNext to have all it needs
2 parents d1c23a5 + 0176b96 commit f95748a

22 files changed

+311
-19
lines changed
1020 KB
Binary file not shown.
-1010 KB
Binary file not shown.
761 KB
Binary file not shown.
-757 KB
Binary file not shown.

LibGit2Sharp.Tests/StashFixture.cs

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,106 @@ public void CanStashAndKeepIndex()
176176
}
177177
}
178178

179+
[Fact]
180+
public void CanStashAndApplyWithOptions()
181+
{
182+
string path = SandboxStandardTestRepo();
183+
using (var repo = new Repository(path))
184+
{
185+
var stasher = Constants.Signature;
186+
187+
const string filename = "staged_file_path.txt";
188+
Touch(repo.Info.WorkingDirectory, filename, "I'm staged\n");
189+
repo.Stage(filename);
190+
191+
repo.Stashes.Add(stasher, "This stash with default options");
192+
Assert.Equal(StashApplyStatus.Applied, repo.Stashes.Apply(0));
193+
194+
Assert.Equal(FileStatus.Untracked, repo.RetrieveStatus(filename));
195+
Assert.Equal(1, repo.Stashes.Count());
196+
197+
repo.Stage(filename);
198+
199+
repo.Stashes.Add(stasher, "This stash with default options");
200+
Assert.Equal(StashApplyStatus.Applied, repo.Stashes.Apply(0, StashApplyModifiers.ReinstateIndex));
201+
202+
Assert.Equal(FileStatus.Added, repo.RetrieveStatus(filename));
203+
Assert.Equal(2, repo.Stashes.Count());
204+
}
205+
}
206+
207+
[Fact]
208+
public void CanStashAndPop()
209+
{
210+
string path = SandboxStandardTestRepo();
211+
using (var repo = new Repository(path))
212+
{
213+
var stasher = Constants.Signature;
214+
215+
const string filename = "staged_file_path.txt";
216+
const string contents = "I'm staged\n";
217+
string contentsNew = "I'm staged" + Environment.NewLine;
218+
Touch(repo.Info.WorkingDirectory, filename, contents);
219+
repo.Stage(filename);
220+
221+
repo.Stashes.Add(stasher, "This stash with default options");
222+
Assert.Equal(StashApplyStatus.Applied, repo.Stashes.Pop(0));
223+
224+
Assert.Equal(FileStatus.Untracked, repo.RetrieveStatus(filename));
225+
Assert.Equal(0, repo.Stashes.Count());
226+
Assert.Equal(contentsNew, File.ReadAllText(Path.Combine(repo.Info.WorkingDirectory, filename)));
227+
}
228+
}
229+
230+
[Fact]
231+
public void StashReportsConflictsWhenReinstated()
232+
{
233+
string path = SandboxStandardTestRepo();
234+
using (var repo = new Repository(path))
235+
{
236+
var stasher = Constants.Signature;
237+
238+
const string filename = "staged_file_path.txt";
239+
const string originalContents = "I'm pre-stash.";
240+
const string filename2 = "unstaged_file_path.txt";
241+
const string newContents = "I'm post-stash.";
242+
243+
Touch(repo.Info.WorkingDirectory, filename, originalContents);
244+
repo.Stage(filename);
245+
Touch(repo.Info.WorkingDirectory, filename2, originalContents);
246+
247+
repo.Stashes.Add(stasher, "This stash with default options");
248+
249+
Touch(repo.Info.WorkingDirectory, filename, newContents);
250+
repo.Stage(filename);
251+
Touch(repo.Info.WorkingDirectory, filename2, newContents);
252+
253+
Assert.Equal(StashApplyStatus.Conflicts, repo.Stashes.Pop(0, StashApplyModifiers.ReinstateIndex));
254+
Assert.Equal(1, repo.Stashes.Count());
255+
Assert.Equal(originalContents, File.ReadAllText(Path.Combine(repo.Info.WorkingDirectory, filename)));
256+
Assert.Equal(originalContents, File.ReadAllText(Path.Combine(repo.Info.WorkingDirectory, filename2)));
257+
258+
}
259+
}
260+
261+
[Fact]
262+
public void StashReportsExistingInWorkDir()
263+
{
264+
string path = SandboxStandardTestRepo();
265+
using (var repo = new Repository(path))
266+
{
267+
var stasher = Constants.Signature;
268+
269+
const string filename = "unstaged_file_path.txt";
270+
Touch(repo.Info.WorkingDirectory, filename, "I'm unstaged\n");
271+
272+
repo.Stashes.Add(stasher, "This stash with default options", StashModifiers.IncludeUntracked);
273+
Touch(repo.Info.WorkingDirectory, filename, "I'm another unstaged\n");
274+
275+
Assert.Equal(StashApplyStatus.UntrackedExist, repo.Stashes.Pop(0));
276+
}
277+
}
278+
179279
[Fact]
180280
public void CanStashIgnoredFiles()
181281
{

LibGit2Sharp.Tests/ssh_used.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
False
1+
True

LibGit2Sharp/Core/GitCheckoutOpts.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ internal struct GitCheckoutOpts
158158
public GitStrArray paths;
159159

160160
public IntPtr baseline;
161+
public IntPtr baseline_index;
161162
public IntPtr target_directory;
162163

163164
public IntPtr ancestor_label;

LibGit2Sharp/Core/GitMergeOpts.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ internal struct GitMergeOpts
3131
/// Flags for automerging content.
3232
/// </summary>
3333
public MergeFileFavor MergeFileFavorFlags;
34+
35+
/// <summary>
36+
/// Flags to use for file merging.
37+
/// </summary>
38+
public GitMergeFileFlags FileFlags;
3439
}
3540

3641
/// <summary>
@@ -105,4 +110,53 @@ internal enum GitMergeTreeFlags
105110
/// </summary>
106111
GIT_MERGE_TREE_FIND_RENAMES = (1 << 0),
107112
}
113+
114+
[Flags]
115+
internal enum GitMergeFileFlags
116+
{
117+
/// <summary>
118+
/// No options.
119+
/// </summary>
120+
GIT_MERGE_FILE_DEFAULT = 0,
121+
122+
/// <summary>
123+
/// Creates standard conflicted merge files.
124+
/// </summary>
125+
GIT_MERGE_FILE_STYLE_MERGE = (1 << 0),
126+
127+
/// <summary>
128+
/// Creates diff3 style files.
129+
/// </summary>
130+
GIT_MERGE_FILE_STYLE_DIFF3 = (1 << 1),
131+
132+
/// <summary>
133+
/// Condenses non-alphanumeric regions for simplified diff files.
134+
/// </summary>
135+
GIT_MERGE_FILE_SIMPLIFY_ALNUM = (1 << 2),
136+
137+
/// <summary>
138+
/// Ignores all whitespace.
139+
/// </summary>
140+
GIT_MERGE_FILE_IGNORE_WHITESPACE = (1 << 3),
141+
142+
/// <summary>
143+
/// Ignores changes in amount of whitespace.
144+
/// </summary>
145+
GIT_MERGE_FILE_IGNORE_WHITESPACE_CHANGE = (1 << 4),
146+
147+
/// <summary>
148+
/// Ignores whitespace at the end of the line.
149+
/// </summary>
150+
GIT_MERGE_FILE_IGNORE_WHITESPACE_EOL = (1 << 5),
151+
152+
/// <summary>
153+
/// Uses the 'patience' diff algorithm.
154+
/// </summary>
155+
GIT_MERGE_FILE_DIFF_PATIENCE = (1 << 6),
156+
157+
/// <summary>
158+
/// Take extra time to find the minimal diff.
159+
/// </summary>
160+
GIT_MERGE_FILE_DIFF_MINIMAL = (1 << 7),
161+
}
108162
}

LibGit2Sharp/Core/GitSmartSubtransportRegistration.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ internal class GitSmartSubtransportRegistration
88
{
99
public IntPtr SubtransportCallback;
1010
public uint Rpc;
11+
public IntPtr Param;
1112

1213
public delegate int create_callback(
1314
out IntPtr subtransport,
14-
IntPtr transport);
15+
IntPtr transport,
16+
IntPtr param);
1517
}
1618
}

LibGit2Sharp/Core/NativeDllName.cs

Lines changed: 1 addition & 1 deletion
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-9bbc8f3";
5+
public const string Name = "git2-14a29d2";
66
}
77
}

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ internal static extern int git_note_remove(
744744

745745
[DllImport(libgit2)]
746746
internal static extern int git_note_default_ref(
747-
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(LaxUtf8NoCleanupMarshaler))] out string notes_ref,
747+
GitBuf buf,
748748
RepositorySafeHandle repo);
749749

750750
internal delegate int git_note_foreach_cb(
@@ -1343,6 +1343,20 @@ internal static extern int git_stash_foreach(
13431343
[DllImport(libgit2)]
13441344
internal static extern int git_stash_drop(RepositorySafeHandle repo, UIntPtr index);
13451345

1346+
[DllImport(libgit2)]
1347+
internal static extern int git_stash_apply(
1348+
RepositorySafeHandle repo,
1349+
UIntPtr index,
1350+
ref GitCheckoutOpts opts,
1351+
StashApplyModifiers flags);
1352+
1353+
[DllImport(libgit2)]
1354+
internal static extern int git_stash_pop(
1355+
RepositorySafeHandle repo,
1356+
UIntPtr index,
1357+
ref GitCheckoutOpts opts,
1358+
StashApplyModifiers flags);
1359+
13461360
[DllImport(libgit2)]
13471361
internal static extern int git_status_file(
13481362
out FileStatus statusflags,

LibGit2Sharp/Core/Proxy.cs

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,12 +1298,12 @@ public static ObjectId git_note_create(
12981298
public static string git_note_default_ref(RepositorySafeHandle repo)
12991299
{
13001300
using (ThreadAffinity())
1301+
using (var buf = new GitBuf())
13011302
{
1302-
string notes_ref;
1303-
int res = NativeMethods.git_note_default_ref(out notes_ref, repo);
1303+
int res = NativeMethods.git_note_default_ref(buf, repo);
13041304
Ensure.ZeroResult(res);
13051305

1306-
return notes_ref;
1306+
return LaxUtf8Marshaler.FromNative(buf.ptr);
13071307
}
13081308
}
13091309

@@ -2719,7 +2719,47 @@ public static void git_stash_drop(RepositorySafeHandle repo, int index)
27192719
using (ThreadAffinity())
27202720
{
27212721
int res = NativeMethods.git_stash_drop(repo, (UIntPtr) index);
2722-
Ensure.BooleanResult(res);
2722+
Ensure.ZeroResult(res);
2723+
}
2724+
}
2725+
2726+
private static StashApplyStatus get_stash_status(int res)
2727+
{
2728+
if (res == (int)GitErrorCode.MergeConflict)
2729+
{
2730+
return StashApplyStatus.Conflicts;
2731+
}
2732+
2733+
if (res == (int)GitErrorCode.Exists)
2734+
{
2735+
return StashApplyStatus.UntrackedExist;
2736+
}
2737+
2738+
Ensure.ZeroResult(res);
2739+
return StashApplyStatus.Applied;
2740+
}
2741+
2742+
public static StashApplyStatus git_stash_apply(
2743+
RepositorySafeHandle repo,
2744+
int index,
2745+
ref GitCheckoutOpts opts,
2746+
StashApplyModifiers flags)
2747+
{
2748+
using (ThreadAffinity())
2749+
{
2750+
return get_stash_status(NativeMethods.git_stash_apply(repo, (UIntPtr)index, ref opts, flags));
2751+
}
2752+
}
2753+
2754+
public static StashApplyStatus git_stash_pop(
2755+
RepositorySafeHandle repo,
2756+
int index,
2757+
ref GitCheckoutOpts opts,
2758+
StashApplyModifiers flags)
2759+
{
2760+
using (ThreadAffinity())
2761+
{
2762+
return get_stash_status(NativeMethods.git_stash_pop(repo, (UIntPtr)index, ref opts, flags));
27232763
}
27242764
}
27252765

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
<Compile Include="RevertResult.cs" />
135135
<Compile Include="RevertOptions.cs" />
136136
<Compile Include="StageOptions.cs" />
137+
<Compile Include="StashApplyStatus.cs" />
137138
<Compile Include="StatusOptions.cs" />
138139
<Compile Include="SimilarityOptions.cs" />
139140
<Compile Include="Log.cs" />

LibGit2Sharp/SmartSubtransportRegistration.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ private static class EntryPoints
8080

8181
private static int Subtransport(
8282
out IntPtr subtransport,
83-
IntPtr transport)
83+
IntPtr transport,
84+
IntPtr payload)
8485
{
8586
subtransport = IntPtr.Zero;
8687

LibGit2Sharp/StashApplyStatus.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace LibGit2Sharp
7+
{
8+
/// <summary>
9+
/// The status of what happened as a result of a stash application.
10+
/// </summary>
11+
public enum StashApplyStatus
12+
{
13+
/// <summary>
14+
/// The changes were successfully stashed.
15+
/// </summary>
16+
Applied,
17+
18+
/// <summary>
19+
/// The stash application resulted in conflicts.
20+
/// </summary>
21+
Conflicts,
22+
23+
/// <summary>
24+
/// The stash application was not applied due to existing
25+
/// untracked files that would be overwritten by the stash
26+
/// contents.
27+
/// </summary>
28+
UntrackedExist,
29+
}
30+
}

LibGit2Sharp/StashCollection.cs

Lines changed: 30 additions & 0 deletions
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+
/// Applies a single stashed state from the stash list
119+
/// </summary>
120+
/// <param name="index">the index of the stash to remove (0 being the most recent one).</param>
121+
/// <param name="options">the options to use for checking out the stash.</param>
122+
/// <param name="flags">the flags to use for applying the changes.</param>
123+
public virtual StashApplyStatus Apply(int index, StashApplyModifiers flags = StashApplyModifiers.Default, CheckoutOptions options = null)
124+
{
125+
using (GitCheckoutOptsWrapper checkoutOptionsWrapper = new GitCheckoutOptsWrapper(options ?? new CheckoutOptions()))
126+
{
127+
var opts = checkoutOptionsWrapper.Options;
128+
return Proxy.git_stash_apply(repo.Handle, index, ref opts, flags);
129+
}
130+
}
131+
132+
/// <summary>
133+
/// Pops a single stashed state from the stash list
134+
/// </summary>
135+
/// <param name="index">the index of the stash to remove (0 being the most recent one).</param>
136+
/// <param name="options">the options to use for checking out the stash.</param>
137+
/// <param name="flags">the flags to use for applying the changes.</param>
138+
public virtual StashApplyStatus Pop(int index, StashApplyModifiers flags = StashApplyModifiers.Default, CheckoutOptions options = null)
139+
{
140+
using (GitCheckoutOptsWrapper checkoutOptionsWrapper = new GitCheckoutOptsWrapper(options ?? new CheckoutOptions()))
141+
{
142+
var opts = checkoutOptionsWrapper.Options;
143+
return Proxy.git_stash_pop(repo.Handle, index, ref opts, flags);
144+
}
145+
}
146+
117147
private string DebuggerDisplay
118148
{
119149
get

0 commit comments

Comments
 (0)