Skip to content

Commit bdc8dbe

Browse files
committed
Merge pull request #1219 from libgit2/cmn/reset-checkoutoptions
Expose Reset() with checkout options
2 parents e6f9e97 + a285b5d commit bdc8dbe

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

LibGit2Sharp.Tests/ResetHeadFixture.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ public void HardResetInABareRepositoryThrows()
235235
[Fact]
236236
public void HardResetUpdatesTheContentOfTheWorkingDirectory()
237237
{
238+
bool progressCalled = false;
239+
238240
string path = SandboxStandardTestRepo();
239241
using (var repo = new Repository(path))
240242
{
@@ -245,11 +247,16 @@ public void HardResetUpdatesTheContentOfTheWorkingDirectory()
245247

246248
Assert.True(names.Count > 4);
247249

248-
repo.Reset(ResetMode.Hard, "HEAD~3");
250+
var commit = repo.Lookup<Commit>("HEAD~3");
251+
repo.Reset(ResetMode.Hard, commit, new CheckoutOptions()
252+
{
253+
OnCheckoutProgress = (_path, _completed, _total) => { progressCalled = true; },
254+
});
249255

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

259+
Assert.Equal(true, progressCalled);
253260
Assert.Equal(new[] { ".git", "README", "WillNotBeRemoved.txt", "branch_file.txt", "new.txt", "new_untracked_file.txt" }, names);
254261
}
255262
}

LibGit2Sharp/IRepository.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,15 @@ public interface IRepository : IDisposable
165165
/// <param name="commit">The target commit object.</param>
166166
void Reset(ResetMode resetMode, Commit commit);
167167

168+
/// <summary>
169+
/// Sets <see cref="Head"/> to the specified commit and optionally resets the <see cref="Index"/> and
170+
/// the content of the working tree to match.
171+
/// </summary>
172+
/// <param name="resetMode">Flavor of reset operation to perform.</param>
173+
/// <param name="commit">The target commit object.</param>
174+
/// <param name="opts">Collection of parameters controlling checkout behavior.</param>
175+
void Reset(ResetMode resetMode, Commit commit, CheckoutOptions options);
176+
168177
/// <summary>
169178
/// Replaces entries in the <see cref="Repository.Index"/> with entries from the specified commit.
170179
/// </summary>

LibGit2Sharp/Repository.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -985,15 +985,16 @@ public void Reset(ResetMode resetMode, Commit commit)
985985
}
986986

987987
/// <summary>
988-
/// Sets the current <see cref="Head"/> to the specified commit and optionally resets the <see cref="Index"/> and
988+
/// Sets <see cref="Head"/> to the specified commit and optionally resets the <see cref="Index"/> and
989989
/// the content of the working tree to match.
990990
/// </summary>
991991
/// <param name="resetMode">Flavor of reset operation to perform.</param>
992992
/// <param name="commit">The target commit object.</param>
993993
/// <param name="opts">Collection of parameters controlling checkout behavior.</param>
994-
private void Reset(ResetMode resetMode, Commit commit, IConvertableToGitCheckoutOpts opts)
994+
public void Reset(ResetMode resetMode, Commit commit, CheckoutOptions opts)
995995
{
996996
Ensure.ArgumentNotNull(commit, "commit");
997+
Ensure.ArgumentNotNull(opts, "opts");
997998

998999
using (GitCheckoutOptsWrapper checkoutOptionsWrapper = new GitCheckoutOptsWrapper(opts))
9991000
{

0 commit comments

Comments
 (0)