10000 Adds Reset(ResetOptions resetOptions, Commit commit) method in Reposi… · rlazev/libgit2sharp@0c290c4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0c290c4

Browse files
committed
Adds Reset(ResetOptions resetOptions, Commit commit) method in Repository
1 parent 474cc1c commit 0c290c4

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

LibGit2Sharp.Tests/ResetHeadFixture.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@ public void SoftResetToTheHeadOfARepositoryDoesNotChangeTheTargetOfTheHead()
3535
}
3636
}
3737

38+
[Fact]
39+
public void SoftResetToAParentCommitChangesTheTargetOfTheHead()
40+
{
41+
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
42+
43+
using (var repo = new Repository(path.RepositoryPath))
44+
{
45+
var headCommit = repo.Head.Tip;
46+
var firstCommitParent = headCommit.Parents.First();
47+
repo.Reset(ResetOptions.Soft, firstCommitParent);
48+
49+
Assert.Equal(firstCommitParent 10000 , repo.Head.Tip);
50+
}
51+
}
52+
3853
[Fact]
3954
public void SoftResetSetsTheHeadToTheDereferencedCommitOfAChainedTag()
4055
{
@@ -53,7 +68,8 @@ public void ResettingWithBadParamsThrows()
5368
{
5469
using (var repo = new Repository(BareTestRepoPath))
5570
{
56-
Assert.Throws<ArgumentNullException>(() => repo.Reset(ResetOptions.Soft, null));
71+
Assert.Throws<ArgumentNullException>(() => repo.Reset(ResetOptions.Soft, (string)null));
72+
Assert.Throws<ArgumentNullException>(() => repo.Reset(ResetOptions.Soft, (Commit)null));
5773
Assert.Throws<ArgumentException>(() => repo.Reset(ResetOptions.Soft, ""));
5874
Assert.Throws<LibGit2SharpException>(() => repo.Reset(ResetOptions.Soft, Constants.UnknownSha));
5975
Assert.Throws<LibGit2SharpException>(() => repo.Reset(ResetOptions.Soft, repo.Head.Tip.Tree.Sha));

LibGit2Sharp/IRepository.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ public interface IRepository : IDisposable
117117
/// <returns>The generated <see cref = "Commit" />.</returns>
118118
Commit Commit(string message, Signature author, Signature committer, bool amendPreviousCommit = false);
119119

120+
/// <summary>
121+
/// Sets the current <see cref = "Head" /> to the specified commit and optionally resets the <see cref = "Index" /> and
122+
/// the content of the working tree to match.
123+
/// </summary>
124+
/// <param name = "resetOptions">Flavor of reset operation to perform.</param>
125+
/// <param name = "commit">The target commit object.</param>
126+
void Reset(ResetOptions resetOptions, Commit commit);
127+
120128
/// <summary>
121129
/// Sets the current <see cref = "Repository.Head" /> to the specified commit and optionally resets the <see cref = "Repository.Index" /> and
122130
/// the content of the working tree to match.

LibGit2Sharp/Repository.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,19 @@ private void CheckoutHeadForce(CheckoutProgressHandler onCheckoutProgress)
526526
Proxy.git_checkout_head(this.Handle, options);
527527
}
528528

529+
/// <summary>
530+
/// Sets the current <see cref = "Head" /> to the specified commit and optionally resets the <see cref = "Index" /> and
531+
/// the content of the working tree to match.
532+
/// </summary>
533+
/// <param name = "resetOptions">Flavor of reset operation to perform.</param>
534+
/// <param name = "commit">The target commit object.</param>
535+
public void Reset(ResetOptions resetOptions, Commit commit)
536+
{
537+
Ensure.ArgumentNotNull(commit, "commit");
538+
539+
Proxy.git_reset(handle, commit.Id, resetOptions);
540+
}
541+
529542
/// <summary>
530543
/// Sets the current <see cref = "Head" /> to the specified commit and optionally resets the <see cref = "Index" /> and
531544
/// the content of the working tree to match.
@@ -537,8 +550,7 @@ public void Reset(ResetOptions resetOptions, string committish = "HEAD")
537550
Ensure.ArgumentNotNullOrEmptyString(committish, "committish");
538551

539552
Commit commit = LookupCommit(committish);
540-
541-
Proxy.git_reset(handle, commit.Id, resetOptions);
553+
Reset(resetOptions, commit);
542554
}
543555

544556
/// <summary>

LibGit2Sharp/ResetOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace LibGit2Sharp
22
{
33
/// <summary>
4-
/// Specifies the kind of operation that <see cref="Repository.Reset(LibGit2Sharp.ResetOptions, string)"/> should perform.
4+
/// Specifies the kind of operation that <see cref="IRepository.Reset(LibGit2Sharp.ResetOptions, Commit)"/> should perform.
55
/// </summary>
66
public enum ResetOptions
77
{

0 commit comments

Comments
 (0)
0