Commit d1b7921a48161cf6fe5bb85a5da4c0bdac3c0df7

nulltoken 2012-07-12T11:46:20

revparse: fix disambiguation of refs and abbrev oids

diff --git a/src/revparse.c b/src/revparse.c
index e35c01a..270bdaa 100644
--- a/src/revparse.c
+++ b/src/revparse.c
@@ -147,13 +147,6 @@ static int revparse_lookup_object(git_object **out, git_repository *repo, const 
 	if (error < 0 && error != GIT_ENOTFOUND)
 		return error;
 
-	error = maybe_sha_or_abbrev(out, repo, spec);
-	if (!error)
-		return 0;
-
-	if (error < 0 && error != GIT_ENOTFOUND)
-		return error;
-
 	error = disambiguate_refname(&ref, repo, spec);
 	if (!error) {
 		error = git_object_lookup(out, repo, git_reference_oid(ref), GIT_OBJ_ANY);
@@ -164,6 +157,13 @@ static int revparse_lookup_object(git_object **out, git_repository *repo, const 
 	if (error < 0 && error != GIT_ENOTFOUND)
 		return error;
 
+	error = maybe_sha_or_abbrev(out, repo, spec);
+	if (!error)
+		return 0;
+
+	if (error < 0 && error != GIT_ENOTFOUND)
+		return error;
+
 	giterr_set(GITERR_REFERENCE, "Refspec '%s' not found.", spec);
 	return GIT_ENOTFOUND;
 }
diff --git a/tests-clar/refs/revparse.c b/tests-clar/refs/revparse.c
index aba105b..56d57b2 100644
--- a/tests-clar/refs/revparse.c
+++ b/tests-clar/refs/revparse.c
@@ -354,3 +354,52 @@ void test_refs_revparse__colon(void)
 	test_object(":/packed commit t", "41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9");
 	test_object("test/master^2:branch_file.txt", "45b983be36b73c0788dc9cbcb76cbb80fc7bb057");
 }
+
+void test_refs_revparse__disambiguation(void)
+{
+	/*
+	 * $ git show e90810b
+	 * tag e90810b
+	 * Tagger: Vicent Marti <tanoku@gmail.com>
+	 * Date:   Thu Aug 12 03:59:17 2010 +0200
+	 *
+	 * This is a very simple tag.
+	 *
+	 * commit e90810b8df3e80c413d903f631643c716887138d
+	 * Author: Vicent Marti <tanoku@gmail.com>
+	 * Date:   Thu Aug 5 18:42:20 2010 +0200
+	 *
+	 *     Test commit 2
+	 *
+	 * diff --git a/readme.txt b/readme.txt
+	 * index 6336846..0266163 100644
+	 * --- a/readme.txt
+	 * +++ b/readme.txt
+	 * @@ -1 +1,2 @@
+	 *  Testing a readme.txt
+	 * +Now we add a single line here
+	 *
+	 * $ git show-ref e90810b
+	 * 7b4384978d2493e851f9cca7858815fac9b10980 refs/tags/e90810b
+	 *
+	 */
+	test_object("e90810b", "7b4384978d2493e851f9cca7858815fac9b10980");
+
+	/*
+	 * $ git show e90810
+	 * commit e90810b8df3e80c413d903f631643c716887138d
+	 * Author: Vicent Marti <tanoku@gmail.com>
+	 * Date:   Thu Aug 5 18:42:20 2010 +0200
+	 *
+	 *     Test commit 2
+	 *
+	 * diff --git a/readme.txt b/readme.txt
+	 * index 6336846..0266163 100644
+	 * --- a/readme.txt
+	 * +++ b/readme.txt
+	 * @@ -1 +1,2 @@
+	 *  Testing a readme.txt
+	 * +Now we add a single line here
+	 */
+	test_object("e90810", "e90810b8df3e80c413d903f631643c716887138d");
+}