Skip to content

Expose Reset() with checkout options #1219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion LibGit2Sharp.Tests/ResetHeadFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ public void HardResetInABareRepositoryThrows()
[Fact]
public void HardResetUpdatesTheContentOfTheWorkingDirectory()
{
bool progressCalled = false;

string path = SandboxStandardTestRepo();
using (var repo = new Repository(path))
{
Expand All @@ -245,11 +247,16 @@ public void HardResetUpdatesTheContentOfTheWorkingDirectory()

Assert.True(names.Count > 4);

repo.Reset(ResetMode.Hard, "HEAD~3");
var commit = repo.Lookup<Commit>("HEAD~3");
repo.Reset(ResetMode.Hard, commit, new CheckoutOptions()
{
OnCheckoutProgress = (_path, _completed, _total) => { progressCalled = true; },
});

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

Assert.Equal(true, progressCalled);
Assert.Equal(new[] { ".git", "README", "WillNotBeRemoved.txt", "branch_file.txt", "new.txt", "new_untracked_file.txt" }, names);
}
}
Expand Down
9 changes: 9 additions & 0 deletions LibGit2Sharp/IRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ public interface IRepository : IDisposable
/// <param name="commit">The target commit object.</param>
void Reset(ResetMode resetMode, Commit commit);

/// <summary>
/// Sets <see cref="Head"/> to the specified commit and optionally resets the <see cref="Index"/> and
/// the content of the working tree to match.
/// </summary>
/// <param name="resetMode">Flavor of reset operation to perform.</param>
/// <param name="commit">The target commit object.</param>
/// <param name="opts">Collection of parameters controlling checkout behavior.</param>
void Reset(ResetMode resetMode, Commit commit, CheckoutOptions options);

/// <summary>
/// Replaces entries in the <see cref="Repository.Index"/> with entries from the specified commit.
/// </summary>
Expand Down
5 changes: 3 additions & 2 deletions LibGit2Sharp/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -985,15 +985,16 @@ public void Reset(ResetMode resetMode, Commit commit)
}

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

using (GitCheckoutOptsWrapper checkoutOptionsWrapper = new GitCheckoutOptsWrapper(opts))
{
Expand Down