diff options
-rw-r--r-- | LibGit2Sharp.Tests/ResetHeadFixture.cs | 18 | ||||
-rw-r--r-- | LibGit2Sharp/IRepository.cs | 8 | ||||
-rw-r--r-- | LibGit2Sharp/Repository.cs | 16 | ||||
-rw-r--r-- | LibGit2Sharp/ResetOptions.cs | 2 |
4 files changed, 40 insertions, 4 deletions
diff --git a/LibGit2Sharp.Tests/ResetHeadFixture.cs b/LibGit2Sharp.Tests/ResetHeadFixture.cs index a6d94aaf..d757633c 100644 --- a/LibGit2Sharp.Tests/ResetHeadFixture.cs +++ b/LibGit2Sharp.Tests/ResetHeadFixture.cs @@ -36,6 +36,21 @@ namespace LibGit2Sharp.Tests } [Fact] + public void SoftResetToAParentCommitChangesTheTargetOfTheHead() + { + TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(); + + using (var repo = new Repository(path.RepositoryPath)) + { + var headCommit = repo.Head.Tip; + var firstCommitParent = headCommit.Parents.First(); + repo.Reset(ResetOptions.Soft, firstCommitParent); + + Assert.Equal(firstCommitParent, repo.Head.Tip); + } + } + + [Fact] public void SoftResetSetsTheHeadToTheDereferencedCommitOfAChainedTag() { TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(); @@ -53,7 +68,8 @@ namespace LibGit2Sharp.Tests { using (var repo = new Repository(BareTestRepoPath)) { - Assert.Throws<ArgumentNullException>(() => repo.Reset(ResetOptions.Soft, null)); + Assert.Throws<ArgumentNullException>(() => repo.Reset(ResetOptions.Soft, (string)null)); + Assert.Throws<ArgumentNullException>(() => repo.Reset(ResetOptions.Soft, (Commit)null)); Assert.Throws<ArgumentException>(() => repo.Reset(ResetOptions.Soft, "")); Assert.Throws<LibGit2SharpException>(() => repo.Reset(ResetOptions.Soft, Constants.UnknownSha)); Assert.Throws<LibGit2SharpException>(() => repo.Reset(ResetOptions.Soft, repo.Head.Tip.Tree.Sha)); diff --git a/LibGit2Sharp/IRepository.cs b/LibGit2Sharp/IRepository.cs index fb2f3b81..ed6203cb 100644 --- a/LibGit2Sharp/IRepository.cs +++ b/LibGit2Sharp/IRepository.cs @@ -118,6 +118,14 @@ namespace LibGit2Sharp Commit Commit(string message, Signature author, Signature committer, bool amendPreviousCommit = false); /// <summary> + /// Sets the current <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 = "resetOptions">Flavor of reset operation to perform.</param> + /// <param name = "commit">The target commit object.</param> + void Reset(ResetOptions resetOptions, Commit commit); + + /// <summary> /// Sets the current <see cref = "Repository.Head" /> to the specified commit and optionally resets the <see cref = "Repository.Index" /> and /// the content of the working tree to match. /// </summary> diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs index cb628026..6d38c9a9 100644 --- a/LibGit2Sharp/Repository.cs +++ b/LibGit2Sharp/Repository.cs @@ -531,14 +531,26 @@ namespace LibGit2Sharp /// the content of the working tree to match. /// </summary> /// <param name = "resetOptions">Flavor of reset operation to perform.</param> + /// <param name = "commit">The target commit object.</param> + public void Reset(ResetOptions resetOptions, Commit commit) + { + Ensure.ArgumentNotNull(commit, "commit"); + + Proxy.git_reset(handle, commit.Id, resetOptions); + } + + /// <summary> + /// Sets the current <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 = "resetOptions">Flavor of reset operation to perform.</param> /// <param name = "committish">A revparse spec for the target commit object.</param> public void Reset(ResetOptions resetOptions, string committish = "HEAD") { Ensure.ArgumentNotNullOrEmptyString(committish, "committish"); Commit commit = LookupCommit(committish); - - Proxy.git_reset(handle, commit.Id, resetOptions); + Reset(resetOptions, commit); } /// <summary> diff --git a/LibGit2Sharp/ResetOptions.cs b/LibGit2Sharp/ResetOptions.cs index 3510d496..66f009ed 100644 --- a/LibGit2Sharp/ResetOptions.cs +++ b/LibGit2Sharp/ResetOptions.cs @@ -1,7 +1,7 @@ namespace LibGit2Sharp { /// <summary> - /// Specifies the kind of operation that <see cref="Repository.Reset(LibGit2Sharp.ResetOptions, string)"/> should perform. + /// Specifies the kind of operation that <see cref="IRepository.Reset(LibGit2Sharp.ResetOptions, Commit)"/> should perform. /// </summary> public enum ResetOptions { |