8000 Deprecated ResetOptions in favor ResetMode. · apfunk/libgit2sharp@2553c80 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2553c80

Browse files
author
Pavel Belousov
committed
Deprecated ResetOptions in favor ResetMode.
1 parent 5e62858 commit 2553c80

16 files changed

+93
-29
lines changed

LibGit2Sharp.Tests/BranchFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ public void DetachedHeadIsNotATrackingBranch()
893893
string path = CloneStandardTestRepo();
894894
using (var repo = new Repository(path))
895895
{
896-
repo.Reset(ResetOptions.Hard);
896+
repo.Reset(ResetMode.Hard);
897897
repo.RemoveUntrackedFiles();
898898

899899
string headSha = repo.Head.Tip.Sha;

LibGit2Sharp.Tests/CheckoutFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ private void PopulateBasicRepository(IRepository repo)
10391039
private void ResetAndCleanWorkingDirectory(IRepository repo)
10401040
{
10411041
// Reset the index and the working tree.
1042-
repo.Reset(ResetOptions.Hard);
1042+
repo.Reset(ResetMode.Hard);
10431043

10441044
// Clean the working directory.
10451045
repo.RemoveUntrackedFiles();

LibGit2Sharp.Tests/CommitFixture.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void CanCorrectlyCountCommitsWhenSwitchingToAnotherBranch()
2929
using (var repo = new Repository(path))
3030
{
3131
// Hard reset and then remove untracked files
32-
repo.Reset(ResetOptions.Hard);
32+
repo.Reset(ResetMode.Hard);
3333
repo.RemoveUntrackedFiles();
3434

3535
repo.Checkout("test");
@@ -246,7 +246,7 @@ public void CanEnumerateFromDetachedHead()
246246
using (var repoClone = new Repository(path))
247247
{
248248
// Hard reset and then remove untracked files
249-
repoClone.Reset(ResetOptions.Hard);
249+
repoClone.Reset(ResetMode.Hard);
250250
repoClone.RemoveUntrackedFiles();
251251

252252
string headSha = repoClone.Head.Tip.Sha;
@@ -550,7 +550,7 @@ public void CommitParentsAreMergeHeads()
550550
string path = CloneStandardTestRepo();
551551
using (var repo = new Repository(path))
552552
{
553-
repo.Reset(ResetOptions.Hard, "c47800");
553+
repo.Reset(ResetMode.Hard, "c47800");
554554

555555
CreateAndStageANewFile(repo);
556556

@@ -764,7 +764,7 @@ public void CanAmendACommitWithMoreThanOneParent()
764764
Assert.NotNull(mergedCommit);
765765
Assert.Equal(2, mergedCommit.Parents.Count());
766766

767-
repo.Reset(ResetOptions.Soft, mergedCommit.Sha);
767+
repo.Reset(ResetMode.Soft, mergedCommit.Sha);
768768

769769
CreateAndStageANewFile(repo);
770770
const string commitMessage = "I'm rewriting the history!";

LibGit2Sharp.Tests/FetchHeadFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void CanIterateFetchHead(string url)
3838

3939
using (var repo = new Repository(clonedRepoPath))
4040
{
41-
repo.Reset(ResetOptions.Hard, "HEAD~2");
41+
repo.Reset(ResetMode.Hard, "HEAD~2");
4242

4343
// Create a file, stage it, and commit it.
4444
const string filename = "b.txt";

LibGit2Sharp.Tests/MergeFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void SoftResetARepoWithUnmergedEntriesThrows()
4343
var headCommit = repo.Head.Tip;
4444
var firstCommitParent = headCommit.Parents.First();
4545
Assert.Throws<UnmergedIndexEntriesException>(
46-
() => repo.Reset(ResetOptions.Soft, firstCommitParent));
46+
() => repo.Reset(ResetMode.Soft, firstCommitParent));
4747
}
4848
}
4949

LibGit2Sharp.Tests/ObjectDatabaseFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ public void CanCreateATreeContainingAGitLinkFromAnUntrackedSubmoduleInTheWorking
314314

315315
var commitWithSubmodule = repo.ObjectDatabase.CreateCommit("Submodule!", Constants.Signature, Constants.Signature, tree,
316316
new[] { repo.Head.Tip });
317-
repo.Reset(ResetOptions.Soft, commitWithSubmodule);
317+
repo.Reset(ResetMode.Soft, commitWithSubmodule);
318318

319319
var submodule = repo.Submodules[submodulePath];
320320
Assert.NotNull(submodule);

LibGit2Sharp.Tests/RepositoryOptionsFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private string MeanwhileInAnotherDimensionAnEvilMastermindIsAtWork(string workin
127127
{
128128
Assert.Equal(Path.GetFullPath(newWorkdir) + Path.DirectorySeparatorChar, Path.GetFullPath(sneakyRepo.Info.WorkingDirectory));
129129

130-
sneakyRepo.Reset(ResetOptions.Mixed, sneakyRepo.Head.Tip.Sha);
130+
sneakyRepo.Reset(ResetMode.Mixed, sneakyRepo.Head.Tip.Sha);
131131

132132
const string filename = "zomg.txt";
133133
Touch(sneakyRepo.Info.WorkingDirectory, filename, "I'm being sneaked in!\n");

LibGit2Sharp.Tests/ResetHeadFixture.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public void ResetANewlyInitializedRepositoryThrows(bool isBare)
1818

1919
using (var repo = new Repository(repoPath))
2020
{
21-
Assert.Throws<LibGit2SharpException>(() => repo.Reset(ResetOptions.Soft));
21+
Assert.Throws<LibGit2SharpException>(() => repo.Reset(ResetMode.Soft));
2222
}
2323
}
2424

@@ -30,7 +30,7 @@ public void SoftResetToTheHeadOfARepositoryDoesNotChangeTheTargetOfTheHead()
3030
{
3131
Branch oldHead = repo.Head;
3232

33-
repo.Reset(ResetOptions.Soft);
33+
repo.Reset(ResetMode.Soft);
3434

3535
Assert.Equal(oldHead, repo.Head);
3636
}
@@ -44,7 +44,7 @@ public void SoftResetToAParentCommitChangesTheTargetOfTheHead()
4444
{
4545
var headCommit = repo.Head.Tip;
4646
var firstCommitParent = headCommit.Parents.First();
47-
repo.Reset(ResetOptions.Soft, firstCommitParent);
47+
repo.Reset(ResetMode.Soft, firstCommitParent);
4848

4949
Assert.Equal(firstCommitParent, repo.Head.Tip);
5050
}
@@ -57,7 +57,7 @@ public void SoftResetSetsTheHeadToTheDereferencedCommitOfAChainedTag()
5757
using (var repo = new Repository(path))
5858
{
5959
Tag tag = repo.Tags["test"];
60-
repo.Reset(ResetOptions.Soft, tag.CanonicalName);
60+
repo.Reset(ResetMode.Soft, tag.CanonicalName);
6161
Assert.Equal("e90810b8df3e80c413d903f631643c716887138d", repo.Head.Tip.Sha);
6262
}
6363
}
@@ -67,11 +67,11 @@ public void ResettingWithBadParamsThrows()
6767
{
6868
using (var repo = new Repository(BareTestRepoPath))
6969
{
70-
Assert.Throws<ArgumentNullException>(() => repo.Reset(ResetOptions.Soft, (string)null));
71-
Assert.Throws<ArgumentNullException>(() => repo.Reset(ResetOptions.Soft, (Commit)null));
72-
Assert.Throws<ArgumentException>(() => repo.Reset(ResetOptions.Soft, ""));
73-
Assert.Throws<LibGit2SharpException>(() => repo.Reset(ResetOptions.Soft, Constants.UnknownSha));
74-
Assert.Throws<LibGit2SharpException>(() => repo.Reset(ResetOptions.Soft, repo.Head.Tip.Tree.Sha));
70+
Assert.Throws<ArgumentNullException>(() => repo.Reset(ResetMode.Soft, (string)null));
71+
Assert.Throws<ArgumentNullException>(() => repo.Reset(ResetMode.Soft, (Commit)null));
72+
Assert.Throws<ArgumentException>(() => repo.Reset(ResetMode.Soft, ""));
73+
Assert.Throws<LibGit2SharpException>(() => repo.Reset(ResetMode.Soft, Constants.UnknownSha));
74+
Assert.Throws<LibGit2SharpException>(() => repo.Reset(ResetMode.Soft, repo.Head.Tip.Tree.Sha));
7575
}
7676
}
7777

@@ -110,7 +110,7 @@ private void AssertSoftReset(Func<Branch, string> branchIdentifierRetriever, boo
110110
Assert.Equal(branch.Tip.Sha, repo.Head.Tip.Sha);
111111

112112
/* Reset --soft the Head to a tag through its canonical name */
113-
repo.Reset(ResetOptions.Soft, tag.CanonicalName);
113+
repo.Reset(ResetMode.Soft, tag.CanonicalName);
114114
Assert.Equal(expectedHeadName, repo.Head.Name);
115115
Assert.Equal(tag.Target.Id, repo.Head.Tip.Id);
116116

@@ -122,7 +122,7 @@ private void AssertSoftReset(Func<Branch, string> branchIdentifierRetriever, boo
122122
oldHeadId);
123123

124124
/* Reset --soft the Head to a commit through its sha */
125-
repo.Reset(ResetOptions.Soft, branch.Tip.Sha);
125+
repo.Reset(ResetMode.Soft, branch.Tip.Sha);
126126
Assert.Equal(expectedHeadName, repo.Head.Name);
127127
Assert.Equal(branch.Tip.Sha, repo.Head.Tip.Sha);
128128

@@ -167,7 +167,7 @@ public void MixedResetRefreshesTheIndex()
167167

168168
Tag tag = repo.Tags["mytag"];
169169

170-
repo.Reset(ResetOptions.Mixed, tag.CanonicalName);
170+
repo.Reset(ResetMode.Mixed, tag.CanonicalName);
171171

172172
Assert.Equal(FileStatus.Modified, repo.Index.RetrieveStatus("a.txt"));
173173

@@ -183,7 +183,7 @@ public void MixedResetInABareRepositoryThrows()
183183
{
184184
using (var repo = new Repository(BareTestRepoPath))
185185
{
186-
Assert.Throws<BareRepositoryException>(() => repo.Reset(ResetOptions.Mixed));
186+
Assert.Throws<BareRepositoryException>(() => repo.Reset(ResetMode.Mixed));
187187
}
188188
}
189189

@@ -192,7 +192,7 @@ public void HardResetInABareRepositoryThrows()
192192
{
193193
using (var repo = new Repository(BareTestRepoPath))
194194
{
195-
Assert.Throws<BareRepositoryException>(() => repo.Reset(ResetOptions.Hard));
195+
Assert.Throws<BareRepositoryException>(() => repo.Reset(ResetMode.Hard));
196196
}
197197
}
198198

@@ -209,7 +209,7 @@ public void HardResetUpdatesTheContentOfTheWorkingDirectory()
209209

210210
Assert.True(names.Count > 4);
211211

212-
repo.Reset(ResetOptions.Hard, "HEAD~3");
212+
repo.Reset(ResetMode.Hard, "HEAD~3");
213213

214214
names = new DirectoryInfo(repo.Info.WorkingDirectory).GetFileSystemInfos().Select(fsi => fsi.Name).ToList();
215215
names.Sort(StringComparer.Ordinal);

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ internal static extern int git_repository_state(
993993
internal static extern int git_reset(
994994
RepositorySafeHandle repo,
995995
GitObjectSafeHandle target,
996-
ResetOptions reset_type);
996+
ResetMode reset_type);
997997

998998
[DllImport(libgit2)]
999999
internal static extern int git_revparse_ext(

LibGit2Sharp/Core/Proxy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1837,7 +1837,7 @@ public static FilePath git_repository_workdir(RepositorySafeHandle repo)
18371837
public static void git_reset(
18381838
RepositorySafeHandle repo,
18391839
ObjectId committishId,
1840-
ResetOptions resetKind)
1840+
ResetMode resetKind)
18411841
{
18421842
using (ThreadAffinity())
18431843
using (var osw = new ObjectSafeWrapper(committishId, repo))

LibGit2Sharp/IRepository.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,17 @@ public interface IRepository : IDisposable
170170
/// </summary>
171171
/// <param name="resetOptions">Flavor of reset operation to perform.</param>
172172
/// <param name="commit">The target commit object.</param>
173+
[Obsolete("This method will be removed in the next release. Please use Reset(ResetMode, Commit) instead.")]
173174
void Reset(ResetOptions resetOptions, Commit commit);
174175

176+
/// <summary>
177+
/// Sets the current <see cref="Head"/> to the specified commit and optionally resets the <see cref="Index"/> and
178+
/// the content of the working tree to match.
179+
/// </summary>
180+
/// <param name="resetMode">Flavor of reset operation to perform.</param>
181+
/// <param name="commit">The target commit object.</param>
182+
void Reset(ResetMode resetMode, Commit commit);
183+
175184
/// <summary>
176185
/// Replaces entries in the <see cref="Repository.Index"/> with entries from the specified commit.
177186
/// </summary>

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
<Compile Include="PushOptions.cs" />
7979
<Compile Include="Core\GitBuf.cs" />
8080
<Compile Include="FilteringOptions.cs" />
81+
<Compile Include="ResetMode.cs" />
8182
<Compile Include="UnbornBranchException.cs" />
8283
<Compile Include="LockedFileException.cs" />
8384
<Compile Include="Core\GitRepositoryInitOptions.cs" />

LibGit2Sharp/Repository.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,11 +790,23 @@ private void CheckoutTree(
790790
/// </summary>
791791
/// <param name="resetOptions">Flavor of reset operation to perform.</param>
792792
/// <param name="commit">The target commit object.</param>
793+
[Obsolete("This method will be removed in the next release. Please use Reset(ResetMode, Commit) instead.")]
793794
public void Reset(ResetOptions resetOptions, Commit commit)
795+
{
796+
Reset((ResetMode)resetOptions, commit);
797+
}
798+
799+
/// <summary>
800+
/// Sets the current <see cref="Head"/> to the specified commit and optionally resets the <see cref="Index"/> and
801+
/// the content of the working tree to match.
802+
/// </summary>
803+
/// <param name="resetMode">Flavor of reset operation to perform.</param>
804+
/// <param name="commit">The target commit object.</param>
805+
public void Reset(ResetMode resetMode, Commit commit)
794806
{
795807
Ensure.ArgumentNotNull(commit, "commit");
796808

797-
Proxy.git_reset(handle, commit.Id, resetOptions);
809+
Proxy.git_reset(handle, commit.Id, resetMode);
798810

799811
Refs.Log(Refs.Head).Append(commit.Id, string.Format("reset: moving to {0}", commit.Sha));
800812
}

LibGit2Sharp/RepositoryExtensions.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,26 @@ public static Branch CreateBranch(this IRepository repository, string branchName
145145
/// <param name="repository">The <see cref="Repository"/> being worked with.</param>
146146
/// <param name="resetOptions">Flavor of reset operation to perform.</param>
147147
/// <param name="committish">A revparse spec for the target commit object.</param>
148+
[Obsolete("This method will be removed in the next release. Please use Reset(this IRepository, ResetMode, string) instead.")]
148149
public static void Reset(this IRepository repository, ResetOptions resetOptions, string committish = "HEAD")
150+
{
151+
repository.Reset((ResetMode) resetOptions, committish);
152+
}
153+
154+
/// <summary>
155+
/// Sets the current <see cref="Repository.Head"/> to the specified commit and optionally resets the <see cref="Index"/> and
156+
/// the content of the working tree to match.
157+
/// </summary>
158+
/// <param name="repository">The <see cref="Repository"/> being worked with.</param>
159+
/// <param name="resetMode">Flavor of reset operation to perform.</param>
160+
/// <param name="committish">A revparse spec for the target commit object.</param>
161+
public static void Reset(this IRepository repository, ResetMode resetMode, string committish = "HEAD")
149162
{
150163
Ensure.ArgumentNotNullOrEmptyString(committish, "committish");
151164

152165
Commit commit = LookUpCommit(repository, committish);
153166

154-
repository.Reset(resetOptions, commit);
167+
repository.Reset(resetMode, commit);
155168
}
156169

157170
/// <summary>

LibGit2Sharp/ResetMode.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
namespace LibGit2Sharp
2+
{
3+
/// <summary>
4+
/// Specifies the kind of operation that <see cref="IRepository.Reset(LibGit2Sharp.ResetMode, Commit)"/> should perform.
5+
/// </summary>
6+
public enum ResetMode
7+
{
8+
/// <summary>
9+
/// Moves the branch pointed to by HEAD to the specified commit object.
10+
/// </summary>
11+
Soft = 1,
12+
13+
/// <summary>
14+
/// Moves the branch pointed to by HEAD to the specified commit object and resets the index
15+
/// to the tree recorded by the commit.
16+
/// </summary>
17+
Mixed,
18+
19+
/// <summary>
20+
/// Moves the branch pointed to by HEAD to the specified commit object, resets the index
21+
/// to the tree recorded by the commit and updates the working directory to match the content
22+
/// of the index.
23+
/// </summary>
24+
Hard,
25+
}
26+
}

LibGit2Sharp/ResetOptions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
using System;
2+
13
namespace LibGit2Sharp
24
{
35
/// <summary>
46
/// Specifies the kind of operation that <see cref="IRepository.Reset(LibGit2Sharp.ResetOptions, Commit)"/> should perform.
57
/// </summary>
8+
[Obsolete("This enumeration will be removed in the next release. Please use ResetMode instead.")]
69
public enum ResetOptions
710
{
811
/// <summary>

0 commit comments

Comments
 (0)
0