Commit 279b45b05b05e0dfc496701c4d22e5ea601d0ebf

Carlos Martín Nieto 2012-07-23T21:22:53

revparse: don't allow an empty string Asking the library for "" used to give HEAD, but that's trying to impose a default at the wrong layer. Make it fail.

diff --git a/src/revparse.c b/src/revparse.c
index 6cfea0c..650d7a9 100644
--- a/src/revparse.c
+++ b/src/revparse.c
@@ -705,7 +705,7 @@ int git_revparse_single(git_object **out, git_repository *repo, const char *spec
 
 	*out = NULL;
 
-	do {
+	while (spec[pos]) {
 		switch (spec[pos]) {
 		case '^':
 			if ((error = ensure_base_rev_loaded(&base_rev, &reference, spec, identifier_len, repo, false)) < 0)
@@ -813,9 +813,9 @@ int git_revparse_single(git_object **out, git_repository *repo, const char *spec
 			pos++;
 			identifier_len++;
 		}
-	} while (spec[pos]);
+	}
 
-	if ((error = ensure_base_rev_loaded(&base_rev, &reference, spec, identifier_len, repo, true)) < 0)
+	if ((error = ensure_base_rev_loaded(&base_rev, &reference, spec, identifier_len, repo, false)) < 0)
 		goto cleanup;
 
 	*out = base_rev;
diff --git a/tests-clar/refs/revparse.c b/tests-clar/refs/revparse.c
index 05a9565..02acb88 100644
--- a/tests-clar/refs/revparse.c
+++ b/tests-clar/refs/revparse.c
@@ -64,6 +64,8 @@ void test_refs_revparse__invalid_reference_name(void)
 	cl_git_fail(git_revparse_single(&g_obj, g_repo, "this doesn't make sense"));
 	cl_git_fail(git_revparse_single(&g_obj, g_repo, "this doesn't make sense^1"));
 	cl_git_fail(git_revparse_single(&g_obj, g_repo, "this doesn't make sense~2"));
+	cl_git_fail(git_revparse_single(&g_obj, g_repo, ""));
+
 }
 
 void test_refs_revparse__shas(void)
@@ -74,7 +76,6 @@ void test_refs_revparse__shas(void)
 
 void test_refs_revparse__head(void)
 {
-	test_object("", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
 	test_object("HEAD", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
 	test_object("HEAD^0", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
 	test_object("HEAD~0", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");