Skip to content

Commit fa5eb6a

Browse files
committed
Rename StashOptions into StashModifiers
1 parent 6a257ed commit fa5eb6a

File tree

7 files changed

+64
-15
lines changed

7 files changed

+64
-15
lines changed

LibGit2Sharp.Tests/StashFixture.cs

+13-13
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public void CannotAddStashAgainstBareRepository()
1717
{
1818
var stasher = DummySignature;
1919

20-
Assert.Throws<BareRepositoryException>(() => repo.Stashes.Add(stasher, "My very first stash"));
20+
Assert.Throws<BareRepositoryException>(() => repo.Stashes.Add(stasher, "My very first stash", StashModifiers.Default));
2121
}
2222
}
2323

@@ -31,7 +31,7 @@ public void CanAddAndRemoveStash()
3131

3232
Assert.True(repo.Index.RetrieveStatus().IsDirty);
3333

34-
Stash stash = repo.Stashes.Add(stasher, "My very first stash", StashOptions.IncludeUntracked);
34+
Stash stash = repo.Stashes.Add(stasher, "My very first stash", StashModifiers.IncludeUntracked);
3535

3636
// Check that untracked files are deleted from working directory
3737
Assert.False(File.Exists(Path.Combine(repo.Info.WorkingDirectory, "new_untracked_file.txt")));
@@ -48,7 +48,7 @@ public void CanAddAndRemoveStash()
4848
// Create extra file
4949
Touch(repo.Info.WorkingDirectory, "stash_candidate.txt", "Oh, I'm going to be stashed!\n");
5050

51-
Stash secondStash = repo.Stashes.Add(stasher, "My second stash", StashOptions.IncludeUntracked);
51+
Stash secondStash = repo.Stashes.Add(stasher, "My second stash", StashModifiers.IncludeUntracked);
5252

5353
Assert.NotNull(stash);
5454
Assert.Equal("stash@{0}", stash.CanonicalName);
@@ -83,7 +83,7 @@ public void AddingAStashWithNoMessageGeneratesADefaultOne()
8383
{
8484
var stasher = DummySignature;
8585

86-
Stash stash = repo.Stashes.Add(stasher);
86+
Stash stash = repo.Stashes.Add(stasher, options: StashModifiers.Default);
8787

8888
Assert.NotNull(stash);
8989
Assert.Equal("stash@{0}", stash.CanonicalName);
@@ -100,7 +100,7 @@ public void AddStashWithBadParamsShouldThrows()
100100
string path = CloneStandardTestRepo();
101101
using (var repo = new Repository(path))
102102
{
103-
Assert.Throws<ArgumentNullException>(() => repo.Stashes.Add(null));
103+
Assert.Throws<ArgumentNullException>(() => repo.Stashes.Add(default(Signature), options: StashModifiers.Default));
104104
}
105105
}
106106

@@ -112,12 +112,12 @@ public void StashingAgainstCleanWorkDirShouldReturnANullStash()
112112
{
113113
var stasher = DummySignature;
114114

115-
Stash stash = repo.Stashes.Add(stasher, "My very first stash", StashOptions.IncludeUntracked);
115+
Stash stash = repo.Stashes.Add(stasher, "My very first stash", StashModifiers.IncludeUntracked);
116116

117117
Assert.NotNull(stash);
118118

119119
//Stash against clean working directory
120-
Assert.Null(repo.Stashes.Add(stasher));
120+
Assert.Null(repo.Stashes.Add(stasher, options: StashModifiers.Default));
121121
}
122122
}
123123

@@ -136,7 +136,7 @@ public void CanStashWithoutOptions()
136136
Touch(repo.Info.WorkingDirectory, staged, "I'm staged\n");
137137
repo.Index.Stage(staged);
138138

139-
Stash stash = repo.Stashes.Add(stasher, "Stash with default options");
139+
Stash stash = repo.Stashes.Add(stasher, "Stash with default options", StashModifiers.Default);
140140

141141
Assert.NotNull(stash);
142142

@@ -160,7 +160,7 @@ public void CanStashAndKeepIndex()
160160
Touch(repo.Info.WorkingDirectory, filename, "I'm staged\n");
161161
repo.Index.Stage(filename);
162162

163-
Stash stash = repo.Stashes.Add(stasher, "This stash wil keep index", StashOptions.KeepIndex);
163+
Stash stash = repo.Stashes.Add(stasher, "This stash wil keep index", StashModifiers.KeepIndex);
164164

165165
Assert.NotNull(stash);
166166
Assert.Equal(FileStatus.Added, repo.Index.RetrieveStatus(filename));
@@ -185,7 +185,7 @@ public void CanStashIgnoredFiles()
185185
Assert.True(repo.Ignore.IsPathIgnored(ignoredFilename));
186186

187187
var stasher = DummySignature;
188-
repo.Stashes.Add(stasher, "This stash includes ignore files", StashOptions.IncludeIgnored);
188+
repo.Stashes.Add(stasher, "This stash includes ignore files", StashModifiers.IncludeIgnored);
189189

190190
//TODO : below assertion doesn't pass. Bug?
191191
//Assert.False(File.Exists(ignoredFilePath));
@@ -219,20 +219,20 @@ public void CanGetStashByIndexer()
219219
const string thirdStashMessage = "My third stash";
220220

221221
// Create first stash
222-
Stash firstStash = repo.Stashes.Add(stasher, firstStashMessage, StashOptions.IncludeUntracked);
222+
Stash firstStash = repo.Stashes.Add(stasher, firstStashMessage, StashModifiers.IncludeUntracked);
223223
Assert.NotNull(firstStash);
224224

225225
// Create second stash
226226
Touch(repo.Info.WorkingDirectory, "stash_candidate.txt", "Oh, I'm going to be stashed!\n");
227227

228-
Stash secondStash = repo.Stashes.Add(stasher, secondStashMessage, StashOptions.IncludeUntracked);
228+
Stash secondStash = repo.Stashes.Add(stasher, secondStashMessage, StashModifiers.IncludeUntracked);
229229
Assert.NotNull(secondStash);
230230

231231
// Create third stash
232232
Touch(repo.Info.WorkingDirectory, "stash_candidate_again.txt", "Oh, I'm going to be stashed!\n");
233233

234234

235-
Stash thirdStash = repo.Stashes.Add(stasher, thirdStashMessage, StashOptions.IncludeUntracked);
235+
Stash thirdStash = repo.Stashes.Add(stasher, thirdStashMessage, StashModifiers.IncludeUntracked);
236236
Assert.NotNull(thirdStash);
237237

238238
// Get by indexer

LibGit2Sharp/Core/NativeMethods.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ internal static extern int git_stash_save(
10021002
RepositorySafeHandle repo,
10031003
SignatureSafeHandle stasher,
10041004
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(Utf8Marshaler))] string message,
1005-
StashOptions flags);
1005+
StashModifiers flags);
10061006

10071007
internal delegate int git_stash_cb(
10081008
UIntPtr index,

LibGit2Sharp/Core/Proxy.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1885,7 +1885,7 @@ public static ObjectId git_stash_save(
18851885
RepositorySafeHandle repo,
18861886
Signature stasher,
18871887
string prettifiedMessage,
1888-
StashOptions options)
1888+
StashModifiers options)
18891889
{
18901890
using (ThreadAffinity())
18911891
using (SignatureSafeHandle stasherHandle = stasher.BuildHandle())

LibGit2Sharp/LibGit2Sharp.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
<Compile Include="Core\Handles\NullRepositorySafeHandle.cs" />
8787
<Compile Include="GitLink.cs" />
8888
<Compile Include="Core\RepositoryOpenFlags.cs" />
89+
<Compile Include="StashModifiers.cs" />
8990
<Compile Include="TreeEntryTargetType.cs" />
9091
<Compile Include="UnmatchedPathException.cs" />
9192
<Compile Include="Core\Handles\ReflogEntrySafeHandle.cs" />

LibGit2Sharp/StashCollection.cs

+13
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,20 @@ public virtual Stash this[int index]
8282
/// <param name = "message">The message of the stash.</param>
8383
/// <param name = "options">A combination of <see cref="StashOptions"/> flags</param>
8484
/// <returns>the newly created <see cref="Stash"/></returns>
85+
[Obsolete("This method will be removed in the next release. Please use Add(Signature, string, StashModifiers) instead.")]
8586
public virtual Stash Add(Signature stasher, string message = null, StashOptions options = StashOptions.Default)
87+
{
88+
return Add(stasher, message, (StashModifiers) options);
89+
}
90+
91+
/// <summary>
92+
/// Creates a stash with the specified message.
93+
/// </summary>
94+
/// <param name="stasher">The <see cref="Signature"/> of the user who stashes </param>
95+
/// <param name = "message">The message of the stash.</param>
96+
/// <param name = "options">A combination of <see cref="StashOptions"/> flags</param>
97+
/// <returns>the newly created <see cref="Stash"/></returns>
98+
public virtual Stash Add(Signature stasher, string message = null, StashModifiers options = StashModifiers.Default)
8699
{
87100
Ensure.ArgumentNotNull(stasher, "stasher");
88101

LibGit2Sharp/StashModifiers.cs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
3+
namespace LibGit2Sharp
4+
{
5+
///<summary>
6+
/// Options controlling Stash behavior.
7+
///</summary>
8+
[Flags]
9+
public enum StashModifiers
10+
{
11+
/// <summary>
12+
/// Default
13+
/// </summary>
14+
Default = 0,
15+
16+
/// <summary>
17+
/// All changes already added to the index
18+
/// are left intact in the working directory
19+
/// </summary>
20+
KeepIndex = (1 << 0),
21+
22+
/// <summary>
23+
/// All untracked files are also stashed and then
24+
/// cleaned up from the working directory
25+
/// </summary>
26+
IncludeUntracked = (1 << 1),
27+
28+
/// <summary>
29+
/// All ignored files are also stashed and then
30+
/// cleaned up from the working directory
31+
/// </summary>
32+
IncludeIgnored = (1 << 2),
33+
}
34+
}

LibGit2Sharp/StashOptions.cs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace LibGit2Sharp
66
/// Options controlling Stash behavior.
77
///</summary>
88
[Flags]
9+
[Obsolete("This type will be removed in the next release.")]
910
public enum StashOptions
1011
{
1112
/// <summary>

0 commit comments

Comments
 (0)