Skip to content
This repository

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
Collaborator
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
Collaborator
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))
336 337 /// <param name = "type">The kind of <see cref = "GitObject" /> being looked up</param>
337 338 /// <returns>The <see cref = "GitObject" /> or null if it was not found.</returns>
338   - public GitObject Lookup(string shaOrReferenceName, GitObjectType type = GitObjectType.Any)
  339 + public GitObject Lookup(string objectSpec, GitObjectType type = GitObjectType.Any)
2
nulltoken Collaborator
nulltoken added a note

Can you rename this objectish?

Ben Straub Collaborator
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))
344 345 {
345   - ObjectId id;
  346 + var m = Regex.Match(spec, "[^@^ ]*:(.*)");
2
nulltoken Collaborator
nulltoken added a note

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

Ben Straub Collaborator
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))
356 353
357   - if (id == null)
  354 + GitObjectSafeHandle sh;
2
nulltoken Collaborator
nulltoken added a note

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

Ben Straub Collaborator
ben added a note

I think de799b1 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))
17 17 /// <returns></returns>
18   - public static T Lookup<T>(this IRepository repository, string shaOrRef) where T : GitObject
  18 + public static T Lookup<T>(this IRepository repository, string objectSpec) where T : GitObject
2
nulltoken Collaborator
nulltoken added a note

Can you rename this objectish?

Ben Straub Collaborator
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
Collaborator

@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
Collaborator

@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
Collaborator
ben commented

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
Collaborator

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
Collaborator

@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

Showing 1 unique commit by 2 authors.

Aug 14, 2012
Ben Straub Revparse support in Repository.Lookup.
Now running lookups through git_revparse_single.
8c39bd3
This page is out of date. Refresh to see the latest.
23 LibGit2Sharp.Tests/BranchFixture.cs
@@ -89,6 +89,20 @@ public void CanCreateBranchFromCommit()
89 89 }
90 90
91 91 [Fact]
  92 + public void CanCreateBranchFromRevparseSpec()
  93 + {
  94 + TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
  95 + using (var repo = new Repository(path.RepositoryPath))
  96 + {
  97 + const string name = "revparse_branch";
  98 + var target = repo.Lookup<Commit>("master~2");
  99 + Branch newBranch = repo.CreateBranch(name, target);
  100 + Assert.NotNull(newBranch);
  101 + Assert.Equal("9fd738e8f7967c078dceed8190330fc8648ee56a", newBranch.Tip.Sha);
  102 + }
  103 + }
  104 +
  105 + [Fact]
92 106 public void CreatingABranchFromATagPeelsToTheCommit()
93 107 {
94 108 TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
@@ -151,15 +165,6 @@ public void CreatingBranchWithUnknownShaTargetThrows()
151 165 }
152 166
153 167 [Fact]
154   - public void CreatingABranchPointingAtANonCanonicalReferenceThrows()
155   - {
156   - using (var repo = new Repository(BareTestRepoPath))
157   - {
158   - Assert.Throws<LibGit2SharpException>(() => repo.Branches.Add("nocanonicaltarget", "br2"));
159   - }
160   - }
161   -
162   - [Fact]
163 168 public void CreatingBranchWithBadParamsThrows()
164 169 {
165 170 using (var repo = new Repository(BareTestRepoPath))
31 LibGit2Sharp.Tests/RepositoryFixture.cs
@@ -297,6 +297,35 @@ public void CanLookupWhithShortIdentifers()
297 297 }
298 298
299 299 [Fact]
  300 + public void CanLookupUsingRevparseSyntax()
  301 + {
  302 + using (var repo = new Repository(BareTestRepoPath))
  303 + {
  304 + Assert.Null(repo.Lookup<Tree>("master^"));
  305 +
  306 + Assert.NotNull(repo.Lookup("master:new.txt"));
  307 + Assert.NotNull(repo.Lookup<Blob>("master:new.txt"));
  308 + Assert.NotNull(repo.Lookup("master^"));
  309 + Assert.NotNull(repo.Lookup<Commit>("master^"));
  310 + Assert.NotNull(repo.Lookup("master~3"));
  311 + Assert.NotNull(repo.Lookup("HEAD"));
  312 + Assert.NotNull(repo.Lookup("refs/heads/br2"));
  313 + }
  314 + }
  315 +
  316 + [Fact]
  317 + public void CanResolveAmbiguousRevparseSpecs()
  318 + {
  319 + using (var repo = new Repository(BareTestRepoPath))
  320 + {
  321 + var o1 = repo.Lookup("e90810b"); // This resolves to a tag
  322 + Assert.Equal("7b4384978d2493e851f9cca7858815fac9b10980", o1.Sha);
  323 + var o2 = repo.Lookup("e90810b8"); // This resolves to a commit
  324 + Assert.Equal("e90810b8df3e80c413d903f631643c716887138d", o2.Sha);
  325 + }
  326 + }
  327 +
  328 + [Fact]
300 329 public void LookingUpWithBadParamsThrows()
301 330 {
302 331 using (var repo = new Repository(BareTestRepoPath))
@@ -310,7 +339,7 @@ public void LookingUpWithBadParamsThrows()
310 339 }
311 340 }
312 341
313   - [Fact]
  342 + [Fact, SkippableFact(Skip = "libgit2 not ready")]
314 343 public void LookingUpWithATooShortShaThrows()
315 344 {
316 345 using (var repo = new Repository(BareTestRepoPath))
35 LibGit2Sharp.Tests/TagFixture.cs
@@ -54,6 +54,19 @@ public void CanAddALightweightTagFromABranchName()
54 54 }
55 55
56 56 [Fact]
  57 + public void CanAddALightweightTagFromARevparseSpec()
  58 + {
  59 + TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
  60 + using (var repo = new Repository(path.RepositoryPath))
  61 + {
  62 + Tag newTag = repo.Tags.Add("i_am_lightweight", "master^1^2");
  63 + Assert.False(newTag.IsAnnotated);
  64 + Assert.NotNull(newTag);
  65 + Assert.Equal("c47800c7266a2be04c571c04d5a6614691ea99bd", newTag.Target.Sha);
  66 + }
  67 + }
  68 +
  69 + [Fact]
57 70 public void CanAddAndOverwriteALightweightTag()
58 71 {
59 72 TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
@@ -125,6 +138,19 @@ public void CanAddAnAnnotatedTagFromSha()
125 138 }
126 139
127 140 [Fact]
  141 + public void CanAddAnAnnotatedTagFromARevparseSpec()
  142 + {
  143 + TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
  144 + using (var repo = new Repository(path.RepositoryPath))
  145 + {
  146 + Tag newTag = repo.Tags.Add("unit_test", "master^1^2", signatureTim, "a new tag");
  147 + Assert.NotNull(newTag);
  148 + Assert.True(newTag.IsAnnotated);
  149 + Assert.Equal("c47800c7266a2be04c571c04d5a6614691ea99bd", newTag.Target.Sha);
  150 + }
  151 + }
  152 +
  153 + [Fact]
128 154 // Ported from cgit (https://github.com/git/git/blob/1c08bf50cfcf924094eca56c2486a90e2bf1e6e2/t/t7004-tag.sh#L359)
129 155 public void CanAddAnAnnotatedTagWithAnEmptyMessage()
130 156 {
@@ -202,15 +228,6 @@ public void CreatingATagForAnUnknowReferenceThrows()
202 228 }
203 229
204 230 [Fact]
205   - public void CreatingATagForANonCanonicalReferenceThrows()
206   - {
207   - using (var repo = new Repository(BareTestRepoPath))
208   - {
209   - Assert.Throws<LibGit2SharpException>(() => repo.ApplyTag("noncanonicaltarget", "br2"));
210   - }
211   - }
212   -
213   - [Fact]
214 231 // Ported from cgit (https://github.com/git/git/blob/1c08bf50cfcf924094eca56c2486a90e2bf1e6e2/t/t7004-tag.sh#L42)
215 232 public void CreatingATagForAnUnknowObjectIdThrows()
216 233 {
7 LibGit2Sharp.Tests/TreeFixture.cs
@@ -174,8 +174,15 @@ public void CanRetrieveTreeEntryPath()
174 174 TreeEntry anotherInstance = tree["branch_file.txt"];
175 175 Assert.Equal("branch_file.txt", anotherInstance.Path);
176 176
  177 + // From a rev-parse statement
  178 + var revparseTree = repo.Lookup<Tree>("master:1");
  179 + TreeEntry yetAnotherInstance = revparseTree["branch_file.txt"];
  180 + Assert.Equal(completePath, yetAnotherInstance.Path);
  181 +
177 182 Assert.Equal(tree, subTree);
  183 + Assert.Equal(revparseTree, tree);
178 184 Assert.Equal(anotherInstance, anInstance);
  185 + Assert.Equal(yetAnotherInstance, anotherInstance);
179 186 Assert.NotEqual(anotherInstance.Path, anInstance.Path);
180 187 Assert.NotSame(anotherInstance, anInstance);
181 188 }
12 LibGit2Sharp/BranchCollection.cs
@@ -137,14 +137,14 @@ IEnumerator IEnumerable.GetEnumerator()
137 137 /// Create a new local branch with the specified name
138 138 /// </summary>
139 139 /// <param name = "name">The name of the branch.</param>
140   - /// <param name = "shaOrReferenceName">The target which can be sha or a canonical reference name.</param>
  140 + /// <param name = "commitish">Revparse spec for the target commit.</param>
141 141 /// <param name = "allowOverwrite">True to allow silent overwriting a potentially existing branch, false otherwise.</param>
142 142 /// <returns></returns>
143   - public virtual Branch Add(string name, string shaOrReferenceName, bool allowOverwrite = false)
  143 + public virtual Branch Add(string name, string commitish, bool allowOverwrite = false)
144 144 {
145 145 Ensure.ArgumentNotNullOrEmptyString(name, "name");
146 146
147   - ObjectId commitId = repo.LookupCommit(shaOrReferenceName).Id;
  147 + ObjectId commitId = repo.LookupCommit(commitish).Id;
148 148
149 149 using (var osw = new ObjectSafeWrapper(commitId, repo))
150 150 {
@@ -159,13 +159,13 @@ public virtual Branch Add(string name, string shaOrReferenceName, bool allowOver
159 159 /// Create a new local branch with the specified name
160 160 /// </summary>
161 161 /// <param name = "name">The name of the branch.</param>
162   - /// <param name = "shaOrReferenceName">The target which can be sha or a canonical reference name.</param>
  162 + /// <param name = "commitish">Revparse spec for the target commit.</param>
163 163 /// <param name = "allowOverwrite">True to allow silent overwriting a potentially existing branch, false otherwise.</param>
164 164 /// <returns></returns>
165 165 [Obsolete("This method will be removed in the next release. Please use Add() instead.")]
166   - public virtual Branch Create(string name, string shaOrReferenceName, bool allowOverwrite = false)
  166 + public virtual Branch Create(string name, string commitish, bool allowOverwrite = false)
167 167 {
168   - return Add(name, shaOrReferenceName, allowOverwrite);
  168 + return Add(name, commitish, allowOverwrite);
169 169 }
170 170
171 171 /// <summary>
4 LibGit2Sharp/Core/NativeMethods.cs
@@ -640,6 +640,10 @@ public static bool RepositoryStateChecker(RepositorySafeHandle repositoryPtr, Fu
640 640 public static extern FilePath git_repository_workdir(RepositorySafeHandle repository);
641 641
642 642 [DllImport(libgit2)]
  643 + public static extern int git_revparse_single(out GitObjectSafeHandle obj, RepositorySafeHandle repo,
  644 + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string spec);
  645 +
  646 + [DllImport(libgit2)]
643 647 public static extern void git_revwalk_free(IntPtr walker);
644 648
645 649 [DllImport(libgit2)]
8 LibGit2Sharp/IRepository.cs
@@ -69,9 +69,9 @@ public interface IRepository : IDisposable
69 69 /// <summary>
70 70 /// Checkout the specified branch, reference or SHA.
71 71 /// </summary>
72   - /// <param name = "shaOrReferenceName">The sha of the commit, a canonical reference name or the name of the branch to checkout.</param>
  72 + /// <param name = "commitOrBranchSpec">A revparse spec for the commit or branch to checkout.</param>
73 73 /// <returns>The new HEAD.</returns>
74   - Branch Checkout(string shaOrReferenceName);
  74 + Branch Checkout(string commitOrBranchSpec);
75 75
76 76 /// <summary>
77 77 /// 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
84 84 /// <summary>
85 85 /// 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.
86 86 /// </summary>
87   - /// <param name = "shaOrReferenceName">The sha or reference canonical name to lookup.</param>
  87 + /// <param name = "objectish">A revparse spec for the object to lookup.</param>
88 88 /// <param name = "type">The kind of <see cref = "GitObject" /> being looked up</param>
89 89 /// <returns>The <see cref = "GitObject" /> or null if it was not found.</returns>
90   - GitObject Lookup(string shaOrReferenceName, GitObjectType type = GitObjectType.Any);
  90 + GitObject Lookup(string objectish, GitObjectType type = GitObjectType.Any);
91 91
92 92 /// <summary>
93 93 /// Stores the content of the <see cref = "Repository.Index" /> as a new <see cref = "Commit" /> into the repository.
89 LibGit2Sharp/Repository.cs
@@ -4,6 +4,7 @@
4 4 using System.IO;
5 5 using System.Linq;
6 6 using System.Reflection;
  7 +using System.Text.RegularExpressions;
7 8 using LibGit2Sharp.Core;
8 9 using LibGit2Sharp.Core.Compat;
9 10 using LibGit2Sharp.Core.Handles;
@@ -346,61 +347,71 @@ internal GitObject LookupInternal(ObjectId id, GitObjectType type, FilePath know
346 347 /// <summary>
347 348 /// 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.
348 349 /// </summary>
349   - /// <param name = "shaOrReferenceName">The sha or reference canonical name to lookup.</param>
  350 + /// <param name = "objectish">A revparse spec for the object to lookup.</param>
350 351 /// <param name = "type">The kind of <see cref = "GitObject" /> being looked up</param>
351 352 /// <returns>The <see cref = "GitObject" /> or null if it was not found.</returns>
352   - public GitObject Lookup(string shaOrReferenceName, GitObjectType type = GitObjectType.Any)
  353 + public GitObject Lookup(string objectish, GitObjectType type = GitObjectType.Any)
353 354 {
354   - return Lookup(shaOrReferenceName, type, LookUpOptions.None);
  355 + return Lookup(objectish, type, LookUpOptions.None);
355 356 }
356 357
357   - internal GitObject Lookup(string shaOrReferenceName, GitObjectType type, LookUpOptions lookUpOptions)
  358 + private string PathFromRevparseSpec(string spec)
358 359 {
359   - ObjectId id;
  360 + if (spec.StartsWith(":/")) return null;
  361 + if (Regex.IsMatch(spec, @"^:.*:")) return null;
360 362
361   - Reference reference = Refs[shaOrReferenceName];
362   - if (reference != null)
363   - {
364   - id = reference.PeelToTargetObjectId();
365   - }
366   - else
367   - {
368   - ObjectId.TryParseInternal(shaOrReferenceName, out id, IdentifierSize.Shortest);
369   - }
  363 + var m = Regex.Match(spec, @"[^@^ ]*:(.*)");
  364 + return (m.Groups.Count > 1) ? m.Groups[1].Value : null;
  365 + }
  366 +
  367 + internal GitObject Lookup(string objectish, GitObjectType type, LookUpOptions lookUpOptions)
  368 + {
  369 + Ensure.ArgumentNotNullOrEmptyString(objectish, "commitOrBranchSpec");
  370 +
  371 + GitObjectSafeHandle sh;
  372 + int result = NativeMethods.git_revparse_single(out sh, Handle, objectish);
370 373
371   - if (id == null)
  374 + if ((GitErrorCode)result != GitErrorCode.Ok || sh.IsInvalid)
372 375 {
373   - if (lookUpOptions.Has(LookUpOptions.ThrowWhenNoGitObjectHasBeenFound))
  376 + if (lookUpOptions.Has(LookUpOptions.ThrowWhenNoGitObjectHasBeenFound) &&
  377 + result == (int)GitErrorCode.NotFound)
374 378 {
375   - Ensure.GitObjectIsNotNull(null, shaOrReferenceName);
  379 + Ensure.GitObjectIsNotNull(null, objectish);
  380 + }
  381 +
  382 + if (result == (int)GitErrorCode.Ambiguous)
  383 + {
  384 + throw new AmbiguousException(string.Format(CultureInfo.InvariantCulture, "Provided abbreviated ObjectId '{0}' is too short.", objectish));
376 385 }
377 386
378 387 return null;
379 388 }
380 389
381   - GitObject gitObj = Lookup(id, type);
382   -
383   - if (lookUpOptions.Has(LookUpOptions.ThrowWhenNoGitObjectHasBeenFound))
  390 + if (type != GitObjectType.Any && NativeMethods.git_object_type(sh) != type)
384 391 {
385   - Ensure.GitObjectIsNotNull(gitObj, shaOrReferenceName);
  392 + sh.SafeDispose();
  393 + return null;
386 394 }
387 395
388   - if (!lookUpOptions.Has(LookUpOptions.DereferenceResultToCommit))
  396 + var obj = GitObject.CreateFromPtr(sh, GitObject.ObjectIdOf(sh), this, PathFromRevparseSpec(objectish));
  397 + sh.SafeDispose();
  398 +
  399 + if (lookUpOptions.Has(LookUpOptions.DereferenceResultToCommit))
389 400 {
390   - return gitObj;
  401 + return obj.DereferenceToCommit(objectish,
  402 + lookUpOptions.Has(LookUpOptions.ThrowWhenCanNotBeDereferencedToACommit));
391 403 }
392   -
393   - return gitObj.DereferenceToCommit(shaOrReferenceName, lookUpOptions.Has(LookUpOptions.ThrowWhenCanNotBeDereferencedToACommit));
  404 + return obj;
394 405 }
395 406
396 407 /// <summary>
397 408 /// Lookup a commit by its SHA or name, or throw if a commit is not found.
398 409 /// </summary>
399   - /// <param name="shaOrReferenceName">The SHA or name of the commit.</param>
  410 + /// <param name="commitish">A revparse spec for the commit.</param>
400 411 /// <returns>The commit.</returns>
401   - internal Commit LookupCommit(string shaOrReferenceName)
  412 + internal Commit LookupCommit(string commitish)
402 413 {
403   - return (Commit)Lookup(shaOrReferenceName, GitObjectType.Any, LookUpOptions.ThrowWhenNoGitObjectHasBeenFound | LookUpOptions.DereferenceResultToCommit | LookUpOptions.ThrowWhenCanNotBeDereferencedToACommit);
  414 + return (Commit)Lookup(commitish, GitObjectType.Any, LookUpOptions.ThrowWhenNoGitObjectHasBeenFound | LookUpOptions.DereferenceResultToCommit | LookUpOptions.ThrowWhenCanNotBeDereferencedToACommit);
404 415 }
405 416
406 417 /// <summary>
@@ -430,20 +441,20 @@ public static string Discover(string startingPath)
430 441 /// <summary>
431 442 /// Checkout the specified branch, reference or SHA.
432 443 /// </summary>
433   - /// <param name = "shaOrReferenceName">The sha of the commit, a canonical reference name or the name of the branch to checkout.</param>
  444 + /// <param name = "commitOrBranchSpec">A revparse spec for the commit or branch to checkout.</param>
434 445 /// <returns>The new HEAD.</returns>
435   - public Branch Checkout(string shaOrReferenceName)
  446 + public Branch Checkout(string commitOrBranchSpec)
436 447 {
437 448 // TODO: This does not yet checkout (write) the working directory
438 449
439   - var branch = Branches[shaOrReferenceName];
  450 + var branch = Branches[commitOrBranchSpec];
440 451
441 452 if (branch != null)
442 453 {
443 454 return Checkout(branch);
444 455 }
445 456
446   - var commitId = LookupCommit(shaOrReferenceName).Id;
  457 + var commitId = LookupCommit(commitOrBranchSpec).Id;
447 458 Refs.UpdateTarget("HEAD", commitId.Sha);
448 459 return Head;
449 460 }
@@ -466,17 +477,17 @@ public Branch Checkout(Branch branch)
466 477 /// the content of the working tree to match.
467 478 /// </summary>
468 479 /// <param name = "resetOptions">Flavor of reset operation to perform.</param>
469   - /// <param name = "shaOrReferenceName">The sha or reference canonical name of the target commit object.</param>
470   - public void Reset(ResetOptions resetOptions, string shaOrReferenceName = "HEAD")
  480 + /// <param name = "commitish">A revparse spec for the target commit object.</param>
  481 + public void Reset(ResetOptions resetOptions, string commitish = "HEAD")
471 482 {
472   - Ensure.ArgumentNotNullOrEmptyString(shaOrReferenceName, "shaOrReferenceName");
  483 + Ensure.ArgumentNotNullOrEmptyString(commitish, "commitOrBranchSpec");
473 484
474 485 if (resetOptions.Has(ResetOptions.Mixed) && Info.IsBare)
475 486 {
476 487 throw new LibGit2SharpException("Mixed reset is not allowed in a bare repository");
477 488 }
478 489
479   - Commit commit = LookupCommit(shaOrReferenceName);
  490 + Commit commit = LookupCommit(commitish);
480 491
481 492 //TODO: Check for unmerged entries
482 493
@@ -501,16 +512,16 @@ public void Reset(ResetOptions resetOptions, string shaOrReferenceName = "HEAD")
501 512 /// <summary>
502 513 /// Replaces entries in the <see cref="Index"/> with entries from the specified commit.
503 514 /// </summary>
504   - /// <param name = "shaOrReferenceName">The sha or reference canonical name of the target commit object.</param>
  515 + /// <param name = "commitish">A revparse spec for the target commit object.</param>
505 516 /// <param name = "paths">The list of paths (either files or directories) that should be considered.</param>
506   - public void Reset(string shaOrReferenceName = "HEAD", IEnumerable<string> paths = null)
  517 + public void Reset(string commitish = "HEAD", IEnumerable<string> paths = null)
507 518 {
508 519 if (Info.IsBare)
509 520 {
510 521 throw new LibGit2SharpException("Reset is not allowed in a bare repository");
511 522 }
512 523
513   - Commit commit = LookupCommit(shaOrReferenceName);
  524 + Commit commit = LookupCommit(commitish);
514 525 TreeChanges changes = Diff.Compare(commit.Tree, DiffTarget.Index, paths);
515 526
516 527 Index.Reset(changes);
6 LibGit2Sharp/RepositoryExtensions.cs
@@ -13,11 +13,11 @@ public static class RepositoryExtensions
13 13 /// </summary>
14 14 /// <typeparam name = "T"></typeparam>
15 15 /// <param name = "repository">The <see cref = "Repository" /> being looked up.</param>
16   - /// <param name = "shaOrRef">The shaOrRef to lookup.</param>
  16 + /// <param name = "objectish">The revparse spec for the object to lookup.</param>
17 17 /// <returns></returns>
18   - public static T Lookup<T>(this IRepository repository, string shaOrRef) where T : GitObject
  18 + public static T Lookup<T>(this IRepository repository, string objectish) where T : GitObject
19 19 {
20   - return (T)repository.Lookup(shaOrRef, GitObject.TypeToTypeMap[typeof(T)]);
  20 + return (T)repository.Lookup(objectish, GitObject.TypeToTypeMap[typeof (T)]);
21 21 }
22 22
23 23 /// <summary>

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.