Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Revparse #200

Closed
wants to merge 1 commit into from

3 participants

Ben Straub Don't Add Me To Your Organization a.k.a The Travis Bot nulltoken
Ben Straub
ben commented

Fixes #199

This adds rev-parse functionality to libgit2sharp methods which take a shaOrReferenceName parameter, making them much more powerful.

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request fails (merged 11a912df into c191d7e).

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request fails (merged e31a5d35 into c191d7e).

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request fails (merged 50bf147c into c191d7e).

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request fails (merged 650f395c into c191d7e).

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged af54a01e into c191d7e).

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged d37a5884 into c191d7e).

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged be8589c6 into c191d7e).

Ben Straub
ben commented

@nulltoken I think this is ready for review. Was there anything else you wanted from this feature?

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged 4d649ab8 into c191d7e).

LibGit2Sharp/Repository.cs
((6 lines not shown))
/// <param name = "type">The kind of <see cref = "GitObject" /> being looked up</param>
/// <returns>The <see cref = "GitObject" /> or null if it was not found.</returns>
- public GitObject Lookup(string shaOrReferenceName, GitObjectType type = GitObjectType.Any)
+ public GitObject Lookup(string objectSpec, GitObjectType type = GitObjectType.Any)
nulltoken Owner

Can you rename this objectish?

Ben Straub
ben added a note

Done! Is the documentation for this parameter okay? The git documentation doesn't say anything about rev-parse when it mentions "treeish"es or "commitish"es, but it seems to be the right thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
LibGit2Sharp/Repository.cs
((17 lines not shown))
{
- ObjectId id;
+ var m = Regex.Match(spec, "[^@^ ]*:(.*)");
nulltoken Owner

Maybe should we guard against ':/commitmessage' and ':2:blobname' patterns, don't you think so?

Ben Straub
ben added a note

I've fixed this, but there's no way to write a unit test for it. It doesn't seem like this should be a public static method for Repository. Should it go somewhere else, or just leave it without a real unit test?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
LibGit2Sharp/Repository.cs
((35 lines not shown))
- if (id == null)
+ GitObjectSafeHandle sh;
nulltoken Owner

I think this one should be .SafeDispose()d once used.

Ben Straub
ben added a note

I think de799b12f51a9ff7a98e18bd8d59ae428558bcc7 does this correctly. Am I wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
LibGit2Sharp/RepositoryExtensions.cs
((6 lines not shown))
/// <returns></returns>
- public static T Lookup<T>(this IRepository repository, string shaOrRef) where T : GitObject
+ public static T Lookup<T>(this IRepository repository, string objectSpec) where T : GitObject
nulltoken Owner

Can you rename this objectish?

Ben Straub
ben added a note

Done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged de799b12 into c191d7e).

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged 3ac989b2 into c191d7e).

nulltoken
Owner

@benstraub This all looks pretty nice! Could you please rebase on top of vNext and squash this into a single commit?

Was there anything else you wanted from this feature?

I think CommitLog.QueryBy() and some of the methods of the ReferenceCollection namespace may also benefit from some revpars-ing, but let's merge this first.

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged 0b87a4ab into 4bda9ff).

nulltoken
Owner

@benstraub

I think it'd be nice to have revparse return E_AMBIGUOUS where it makes sense. I don't know if there are other causes than a too short oid, though.

So I'd tend to add a Skip alteration to the Fact attribute.

I add the revparse fix to my Todo list.

Ben Straub Revparse support in Repository.Lookup.
Now running lookups through git_revparse_single.
8c39bd3
Ben Straub

I've added the E_AMBIGUOUS topic to my TODO list. :)

Squash complete. Merge at will. :smiley_cat:

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged 8c39bd3 into 4bda9ff).

nulltoken
Owner

Boom! Merged into vNext.

First, there was nothing. Then native... And now, managed... Awesome job! :heart:

I've added the E_AMBIGUOUS topic to my TODO list. :)

Thief! You'd better make it merged sooner rather than later, man. Otherwise, I'll find you... ;-)

nulltoken nulltoken closed this
nulltoken
Owner

@benstraub No more excuse ;p

diff --git a/tests-clar/refs/revparse.c b/tests-clar/refs/revparse.c
index 02acb88..14bd9fb 100644
--- a/tests-clar/refs/revparse.c
+++ b/tests-clar/refs/revparse.c
@@ -442,3 +442,12 @@ void test_refs_revparse__disambiguation(void)
     */
    test_object("e90810", "e90810b8df3e80c413d903f631643c716887138d");
 }
+
+void test_refs_revparse__a_too_short_objectid_returns_EAMBIGUOUS(void)
+{
+   int result;
+   
+   result = git_revparse_single(&g_obj, g_repo, "e90");
+   
+   cl_assert_equal_i(GIT_EAMBIGUOUS, result);
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 14, 2012
  1. Ben Straub

    Revparse support in Repository.Lookup.

    Ben Straub authored ben committed
    Now running lookups through git_revparse_single.
This page is out of date. Refresh to see the latest.
23 LibGit2Sharp.Tests/BranchFixture.cs
View
@@ -89,6 +89,20 @@ public void CanCreateBranchFromCommit()
}
[Fact]
+ public void CanCreateBranchFromRevparseSpec()
+ {
+ TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
+ using (var repo = new Repository(path.RepositoryPath))
+ {
+ const string name = "revparse_branch";
+ var target = repo.Lookup<Commit>("master~2");
+ Branch newBranch = repo.CreateBranch(name, target);
+ Assert.NotNull(newBranch);
+ Assert.Equal("9fd738e8f7967c078dceed8190330fc8648ee56a", newBranch.Tip.Sha);
+ }
+ }
+
+ [Fact]
public void CreatingABranchFromATagPeelsToTheCommit()
{
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
@@ -151,15 +165,6 @@ public void CreatingBranchWithUnknownShaTargetThrows()
}
[Fact]
- public void CreatingABranchPointingAtANonCanonicalReferenceThrows()
- {
- using (var repo = new Repository(BareTestRepoPath))
- {
- Assert.Throws<LibGit2SharpException>(() => repo.Branches.Add("nocanonicaltarget", "br2"));
- }
- }
-
- [Fact]
public void CreatingBranchWithBadParamsThrows()
{
using (var repo = new Repository(BareTestRepoPath))
31 LibGit2Sharp.Tests/RepositoryFixture.cs
View
@@ -297,6 +297,35 @@ public void CanLookupWhithShortIdentifers()
}
[Fact]
+ public void CanLookupUsingRevparseSyntax()
+ {
+ using (var repo = new Repository(BareTestRepoPath))
+ {
+ Assert.Null(repo.Lookup<Tree>("master^"));
+
+ Assert.NotNull(repo.Lookup("master:new.txt"));
+ Assert.NotNull(repo.Lookup<Blob>("master:new.txt"));
+ Assert.NotNull(repo.Lookup("master^"));
+ Assert.NotNull(repo.Lookup<Commit>("master^"));
+ Assert.NotNull(repo.Lookup("master~3"));
+ Assert.NotNull(repo.Lookup("HEAD"));
+ Assert.NotNull(repo.Lookup("refs/heads/br2"));
+ }
+ }
+
+ [Fact]
+ public void CanResolveAmbiguousRevparseSpecs()
+ {
+ using (var repo = new Repository(BareTestRepoPath))
+ {
+ var o1 = repo.Lookup("e90810b"); // This resolves to a tag
+ Assert.Equal("7b4384978d2493e851f9cca7858815fac9b10980", o1.Sha);
+ var o2 = repo.Lookup("e90810b8"); // This resolves to a commit
+ Assert.Equal("e90810b8df3e80c413d903f631643c716887138d", o2.Sha);
+ }
+ }
+
+ [Fact]
public void LookingUpWithBadParamsThrows()
{
using (var repo = new Repository(BareTestRepoPath))
@@ -310,7 +339,7 @@ public void LookingUpWithBadParamsThrows()
}
}
- [Fact]
+ [Fact, SkippableFact(Skip = "libgit2 not ready")]
public void LookingUpWithATooShortShaThrows()
{
using (var repo = new Repository(BareTestRepoPath))
35 LibGit2Sharp.Tests/TagFixture.cs
View
@@ -54,6 +54,19 @@ public void CanAddALightweightTagFromABranchName()
}
[Fact]
+ public void CanAddALightweightTagFromARevparseSpec()
+ {
+ TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
+ using (var repo = new Repository(path.RepositoryPath))
+ {
+ Tag newTag = repo.Tags.Add("i_am_lightweight", "master^1^2");
+ Assert.False(newTag.IsAnnotated);
+ Assert.NotNull(newTag);
+ Assert.Equal("c47800c7266a2be04c571c04d5a6614691ea99bd", newTag.Target.Sha);
+ }
+ }
+
+ [Fact]
public void CanAddAndOverwriteALightweightTag()
{
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
@@ -125,6 +138,19 @@ public void CanAddAnAnnotatedTagFromSha()
}
[Fact]
+ public void CanAddAnAnnotatedTagFromARevparseSpec()
+ {
+ TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
+ using (var repo = new Repository(path.RepositoryPath))
+ {
+ Tag newTag = repo.Tags.Add("unit_test", "master^1^2", signatureTim, "a new tag");
+ Assert.NotNull(newTag);
+ Assert.True(newTag.IsAnnotated);
+ Assert.Equal("c47800c7266a2be04c571c04d5a6614691ea99bd", newTag.Target.Sha);
+ }
+ }
+
+ [Fact]
// Ported from cgit (https://github.com/git/git/blob/1c08bf50cfcf924094eca56c2486a90e2bf1e6e2/t/t7004-tag.sh#L359)
public void CanAddAnAnnotatedTagWithAnEmptyMessage()
{
@@ -202,15 +228,6 @@ public void CreatingATagForAnUnknowReferenceThrows()
}
[Fact]
- public void CreatingATagForANonCanonicalReferenceThrows()
- {
- using (var repo = new Repository(BareTestRepoPath))
- {
- Assert.Throws<LibGit2SharpException>(() => repo.ApplyTag("noncanonicaltarget", "br2"));
- }
- }
-
- [Fact]
// Ported from cgit (https://github.com/git/git/blob/1c08bf50cfcf924094eca56c2486a90e2bf1e6e2/t/t7004-tag.sh#L42)
public void CreatingATagForAnUnknowObjectIdThrows()
{
7 LibGit2Sharp.Tests/TreeFixture.cs
View
@@ -174,8 +174,15 @@ public void CanRetrieveTreeEntryPath()
TreeEntry anotherInstance = tree["branch_file.txt"];
Assert.Equal("branch_file.txt", anotherInstance.Path);
+ // From a rev-parse statement
+ var revparseTree = repo.Lookup<Tree>("master:1");
+ TreeEntry yetAnotherInstance = revparseTree["branch_file.txt"];
+ Assert.Equal(completePath, yetAnotherInstance.Path);
+
Assert.Equal(tree, subTree);
+ Assert.Equal(revparseTree, tree);
Assert.Equal(anotherInstance, anInstance);
+ Assert.Equal(yetAnotherInstance, anotherInstance);
Assert.NotEqual(anotherInstance.Path, anInstance.Path);
Assert.NotSame(anotherInstance, anInstance);
}
12 LibGit2Sharp/BranchCollection.cs
View
@@ -137,14 +137,14 @@ IEnumerator IEnumerable.GetEnumerator()
/// Create a new local branch with the specified name
/// </summary>
/// <param name = "name">The name of the branch.</param>
- /// <param name = "shaOrReferenceName">The target which can be sha or a canonical reference name.</param>
+ /// <param name = "commitish">Revparse spec for the target commit.</param>
/// <param name = "allowOverwrite">True to allow silent overwriting a potentially existing branch, false otherwise.</param>
/// <returns></returns>
- public virtual Branch Add(string name, string shaOrReferenceName, bool allowOverwrite = false)
+ public virtual Branch Add(string name, string commitish, bool allowOverwrite = false)
{
Ensure.ArgumentNotNullOrEmptyString(name, "name");
- ObjectId commitId = repo.LookupCommit(shaOrReferenceName).Id;
+ ObjectId commitId = repo.LookupCommit(commitish).Id;
using (var osw = new ObjectSafeWrapper(commitId, repo))
{
@@ -159,13 +159,13 @@ public virtual Branch Add(string name, string shaOrReferenceName, bool allowOver
/// Create a new local branch with the specified name
/// </summary>
/// <param name = "name">The name of the branch.</param>
- /// <param name = "shaOrReferenceName">The target which can be sha or a canonical reference name.</param>
+ /// <param name = "commitish">Revparse spec for the target commit.</param>
/// <param name = "allowOverwrite">True to allow silent overwriting a potentially existing branch, false otherwise.</param>
/// <returns></returns>
[Obsolete("This method will be removed in the next release. Please use Add() instead.")]
- public virtual Branch Create(string name, string shaOrReferenceName, bool allowOverwrite = false)
+ public virtual Branch Create(string name, string commitish, bool allowOverwrite = false)
{
- return Add(name, shaOrReferenceName, allowOverwrite);
+ return Add(name, commitish, allowOverwrite);
}
/// <summary>
4 LibGit2Sharp/Core/NativeMethods.cs
View
@@ -640,6 +640,10 @@ public static bool RepositoryStateChecker(RepositorySafeHandle repositoryPtr, Fu
public static extern FilePath git_repository_workdir(RepositorySafeHandle repository);
[DllImport(libgit2)]
+ public static extern int git_revparse_single(out GitObjectSafeHandle obj, RepositorySafeHandle repo,
+ [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string spec);
+
+ [DllImport(libgit2)]
public static extern void git_revwalk_free(IntPtr walker);
[DllImport(libgit2)]
8 LibGit2Sharp/IRepository.cs
View
@@ -69,9 +69,9 @@ public interface IRepository : IDisposable
/// <summary>
/// Checkout the specified branch, reference or SHA.
/// </summary>
- /// <param name = "shaOrReferenceName">The sha of the commit, a canonical reference name or the name of the branch to checkout.</param>
+ /// <param name = "commitOrBranchSpec">A revparse spec for the commit or branch to checkout.</param>
/// <returns>The new HEAD.</returns>
- Branch Checkout(string shaOrReferenceName);
+ Branch Checkout(string commitOrBranchSpec);
/// <summary>
/// Try to lookup an object by its <see cref = "ObjectId" /> and <see cref = "GitObjectType" />. If no matching object is found, null will be returned.
@@ -84,10 +84,10 @@ public interface IRepository : IDisposable
/// <summary>
/// Try to lookup an object by its sha or a reference canonical name and <see cref = "GitObjectType" />. If no matching object is found, null will be returned.
/// </summary>
- /// <param name = "shaOrReferenceName">The sha or reference canonical name to lookup.</param>
+ /// <param name = "objectish">A revparse spec for the object to lookup.</param>
/// <param name = "type">The kind of <see cref = "GitObject" /> being looked up</param>
/// <returns>The <see cref = "GitObject" /> or null if it was not found.</returns>
- GitObject Lookup(string shaOrReferenceName, GitObjectType type = GitObjectType.Any);
+ GitObject Lookup(string objectish, GitObjectType type = GitObjectType.Any);
/// <summary>
/// Stores the content of the <see cref = "Repository.Index" /> as a new <see cref = "Commit" /> into the repository.
89 LibGit2Sharp/Repository.cs
View
@@ -4,6 +4,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
+using System.Text.RegularExpressions;
using LibGit2Sharp.Core;
using LibGit2Sharp.Core.Compat;
using LibGit2Sharp.Core.Handles;
@@ -346,61 +347,71 @@ internal GitObject LookupInternal(ObjectId id, GitObjectType type, FilePath know
/// <summary>
/// Try to lookup an object by its sha or a reference canonical name and <see cref = "GitObjectType" />. If no matching object is found, null will be returned.
/// </summary>
- /// <param name = "shaOrReferenceName">The sha or reference canonical name to lookup.</param>
+ /// <param name = "objectish">A revparse spec for the object to lookup.</param>
/// <param name = "type">The kind of <see cref = "GitObject" /> being looked up</param>
/// <returns>The <see cref = "GitObject" /> or null if it was not found.</returns>
- public GitObject Lookup(string shaOrReferenceName, GitObjectType type = GitObjectType.Any)
+ public GitObject Lookup(string objectish, GitObjectType type = GitObjectType.Any)
{
- return Lookup(shaOrReferenceName, type, LookUpOptions.None);
+ return Lookup(objectish, type, LookUpOptions.None);
}
- internal GitObject Lookup(string shaOrReferenceName, GitObjectType type, LookUpOptions lookUpOptions)
+ private string PathFromRevparseSpec(string spec)
{
- ObjectId id;
+ if (spec.StartsWith(":/")) return null;
+ if (Regex.IsMatch(spec, @"^:.*:")) return null;
- Reference reference = Refs[shaOrReferenceName];
- if (reference != null)
- {
- id = reference.PeelToTargetObjectId();
- }
- else
- {
- ObjectId.TryParseInternal(shaOrReferenceName, out id, IdentifierSize.Shortest);
- }
+ var m = Regex.Match(spec, @"[^@^ ]*:(.*)");
+ return (m.Groups.Count > 1) ? m.Groups[1].Value : null;
+ }
+
+ internal GitObject Lookup(string objectish, GitObjectType type, LookUpOptions lookUpOptions)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(objectish, "commitOrBranchSpec");
+
+ GitObjectSafeHandle sh;
+ int result = NativeMethods.git_revparse_single(out sh, Handle, objectish);
- if (id == null)
+ if ((GitErrorCode)result != GitErrorCode.Ok || sh.IsInvalid)
{
- if (lookUpOptions.Has(LookUpOptions.ThrowWhenNoGitObjectHasBeenFound))
+ if (lookUpOptions.Has(LookUpOptions.ThrowWhenNoGitObjectHasBeenFound) &&
+ result == (int)GitErrorCode.NotFound)
{
- Ensure.GitObjectIsNotNull(null, shaOrReferenceName);
+ Ensure.GitObjectIsNotNull(null, objectish);
+ }
+
+ if (result == (int)GitErrorCode.Ambiguous)
+ {
+ throw new AmbiguousException(string.Format(CultureInfo.InvariantCulture, "Provided abbreviated ObjectId '{0}' is too short.", objectish));
}
return null;
}
- GitObject gitObj = Lookup(id, type);
-
- if (lookUpOptions.Has(LookUpOptions.ThrowWhenNoGitObjectHasBeenFound))
+ if (type != GitObjectType.Any && NativeMethods.git_object_type(sh) != type)
{
- Ensure.GitObjectIsNotNull(gitObj, shaOrReferenceName);
+ sh.SafeDispose();
+ return null;
}
- if (!lookUpOptions.Has(LookUpOptions.DereferenceResultToCommit))
+ var obj = GitObject.CreateFromPtr(sh, GitObject.ObjectIdOf(sh), this, PathFromRevparseSpec(objectish));
+ sh.SafeDispose();
+
+ if (lookUpOptions.Has(LookUpOptions.DereferenceResultToCommit))
{
- return gitObj;
+ return obj.DereferenceToCommit(objectish,
+ lookUpOptions.Has(LookUpOptions.ThrowWhenCanNotBeDereferencedToACommit));
}
-
- return gitObj.DereferenceToCommit(shaOrReferenceName, lookUpOptions.Has(LookUpOptions.ThrowWhenCanNotBeDereferencedToACommit));
+ return obj;
}
/// <summary>
/// Lookup a commit by its SHA or name, or throw if a commit is not found.
/// </summary>
- /// <param name="shaOrReferenceName">The SHA or name of the commit.</param>
+ /// <param name="commitish">A revparse spec for the commit.</param>
/// <returns>The commit.</returns>
- internal Commit LookupCommit(string shaOrReferenceName)
+ internal Commit LookupCommit(string commitish)
{
- return (Commit)Lookup(shaOrReferenceName, GitObjectType.Any, LookUpOptions.ThrowWhenNoGitObjectHasBeenFound | LookUpOptions.DereferenceResultToCommit | LookUpOptions.ThrowWhenCanNotBeDereferencedToACommit);
+ return (Commit)Lookup(commitish, GitObjectType.Any, LookUpOptions.ThrowWhenNoGitObjectHasBeenFound | LookUpOptions.DereferenceResultToCommit | LookUpOptions.ThrowWhenCanNotBeDereferencedToACommit);
}
/// <summary>
@@ -430,20 +441,20 @@ public static string Discover(string startingPath)
/// <summary>
/// Checkout the specified branch, reference or SHA.
/// </summary>
- /// <param name = "shaOrReferenceName">The sha of the commit, a canonical reference name or the name of the branch to checkout.</param>
+ /// <param name = "commitOrBranchSpec">A revparse spec for the commit or branch to checkout.</param>
/// <returns>The new HEAD.</returns>
- public Branch Checkout(string shaOrReferenceName)
+ public Branch Checkout(string commitOrBranchSpec)
{
// TODO: This does not yet checkout (write) the working directory
- var branch = Branches[shaOrReferenceName];
+ var branch = Branches[commitOrBranchSpec];
if (branch != null)
{
return Checkout(branch);
}
- var commitId = LookupCommit(shaOrReferenceName).Id;
+ var commitId = LookupCommit(commitOrBranchSpec).Id;
Refs.UpdateTarget("HEAD", commitId.Sha);
return Head;
}
@@ -466,17 +477,17 @@ public Branch Checkout(Branch branch)
/// the content of the working tree to match.
/// </summary>
/// <param name = "resetOptions">Flavor of reset operation to perform.</param>
- /// <param name = "shaOrReferenceName">The sha or reference canonical name of the target commit object.</param>
- public void Reset(ResetOptions resetOptions, string shaOrReferenceName = "HEAD")
+ /// <param name = "commitish">A revparse spec for the target commit object.</param>
+ public void Reset(ResetOptions resetOptions, string commitish = "HEAD")
{
- Ensure.ArgumentNotNullOrEmptyString(shaOrReferenceName, "shaOrReferenceName");
+ Ensure.ArgumentNotNullOrEmptyString(commitish, "commitOrBranchSpec");
if (resetOptions.Has(ResetOptions.Mixed) && Info.IsBare)
{
throw new LibGit2SharpException("Mixed reset is not allowed in a bare repository");
}
- Commit commit = LookupCommit(shaOrReferenceName);
+ Commit commit = LookupCommit(commitish);
//TODO: Check for unmerged entries
@@ -501,16 +512,16 @@ public void Reset(ResetOptions resetOptions, string shaOrReferenceName = "HEAD")
/// <summary>
/// Replaces entries in the <see cref="Index"/> with entries from the specified commit.
/// </summary>
- /// <param name = "shaOrReferenceName">The sha or reference canonical name of the target commit object.</param>
+ /// <param name = "commitish">A revparse spec for the target commit object.</param>
/// <param name = "paths">The list of paths (either files or directories) that should be considered.</param>
- public void Reset(string shaOrReferenceName = "HEAD", IEnumerable<string> paths = null)
+ public void Reset(string commitish = "HEAD", IEnumerable<string> paths = null)
{
if (Info.IsBare)
{
throw new LibGit2SharpException("Reset is not allowed in a bare repository");
}
- Commit commit = LookupCommit(shaOrReferenceName);
+ Commit commit = LookupCommit(commitish);
TreeChanges changes = Diff.Compare(commit.Tree, DiffTarget.Index, paths);
Index.Reset(changes);
6 LibGit2Sharp/RepositoryExtensions.cs
View
@@ -13,11 +13,11 @@ public static class RepositoryExtensions
/// </summary>
/// <typeparam name = "T"></typeparam>
/// <param name = "repository">The <see cref = "Repository" /> being looked up.</param>
- /// <param name = "shaOrRef">The shaOrRef to lookup.</param>
+ /// <param name = "objectish">The revparse spec for the object to lookup.</param>
/// <returns></returns>
- public static T Lookup<T>(this IRepository repository, string shaOrRef) where T : GitObject
+ public static T Lookup<T>(this IRepository repository, string objectish) where T : GitObject
{
- return (T)repository.Lookup(shaOrRef, GitObject.TypeToTypeMap[typeof(T)]);
+ return (T)repository.Lookup(objectish, GitObject.TypeToTypeMap[typeof (T)]);
}
/// <summary>
Something went wrong with that request. Please try again.