Commit e560aa8ffa7cf143fbd34a5aec44741ae4c77271

Vicent Martí 2012-06-29T12:16:52

Merge pull request #795 from nulltoken/topic/revparse-notfound More git_revparse_single ENOTFOUND use cases

diff --git a/src/revparse.c b/src/revparse.c
index 5050bdf..774beef 100644
--- a/src/revparse.c
+++ b/src/revparse.c
@@ -29,9 +29,10 @@ static void set_invalid_syntax_err(const char *spec)
 static int revparse_lookup_fully_qualifed_ref(git_object **out, git_repository *repo, const char*spec)
 {
 	git_oid resolved;
+	int error;
 
-	if (git_reference_name_to_oid(&resolved, repo, spec) < 0)
-		return GIT_ERROR;
+	if ((error = git_reference_name_to_oid(&resolved, repo, spec)) < 0)
+		return error;
 
 	return git_object_lookup(out, repo, &resolved, GIT_OBJ_ANY);
 }
@@ -107,7 +108,7 @@ static int revparse_lookup_object(git_object **out, git_repository *repo, const 
 	git_buf_free(&refnamebuf);
 
 	giterr_set(GITERR_REFERENCE, "Refspec '%s' not found.", spec);
-	return GIT_ERROR;
+	return GIT_ENOTFOUND;
 }
 
 
@@ -244,7 +245,7 @@ static int walk_ref_history(git_object **out, git_repository *repo, const char *
 						if (numentries < n) {
 							giterr_set(GITERR_REFERENCE, "Reflog for '%s' has only %d entries, asked for %d",
 								git_buf_cstr(&buf), numentries, n);
-							retcode = GIT_ERROR;
+							retcode = GIT_ENOTFOUND;
 						} else {
 							const git_reflog_entry *entry = git_reflog_entry_byindex(reflog, n);
 							const git_oid *oid = git_reflog_entry_oidold(entry);
diff --git a/tests-clar/refs/revparse.c b/tests-clar/refs/revparse.c
index c71e6d8..d28dfa5 100644
--- a/tests-clar/refs/revparse.c
+++ b/tests-clar/refs/revparse.c
@@ -38,10 +38,9 @@ void test_refs_revparse__cleanup(void)
 	cl_setenv("TZ", g_orig_tz);
 }
 
-
 void test_refs_revparse__nonexistant_object(void)
 {
-	cl_git_fail(git_revparse_single(&g_obj, g_repo, "this doesn't exist"));
+	cl_assert_equal_i(GIT_ENOTFOUND, git_revparse_single(&g_obj, g_repo, "this doesn't exist"));
 	cl_git_fail(git_revparse_single(&g_obj, g_repo, "this doesn't exist^1"));
 	cl_git_fail(git_revparse_single(&g_obj, g_repo, "this doesn't exist~2"));
 }
@@ -129,6 +128,9 @@ void test_refs_revparse__reflog(void)
 	cl_git_fail(git_revparse_single(&g_obj, g_repo, "@{-0}"));
 	cl_git_fail(git_revparse_single(&g_obj, g_repo, "@{1000}"));
 
+	cl_assert_equal_i(GIT_ENOTFOUND, git_revparse_single(&g_obj, g_repo, "nope@{0}"));
+	cl_assert_equal_i(GIT_ENOTFOUND, git_revparse_single(&g_obj, g_repo, "master@{31415}"));
+
 	test_object("@{-2}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
 	test_object("@{-1}", "a4a7dce85cf63874e984719f4fdd239f5145052f");
 	test_object("master@{0}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");