Commit f470b00b037cfcd40e19e88913a9a8b64d98288f

Russell Belfer 2013-05-01T15:48:40

Fix one error not reported in revparse There are many paths through revparse that may return an error code without reporting an error, I believe. This fixes one of them. Because of the backtracking in revparse, it is pretty complicated to fix the others.

diff --git a/src/revparse.c b/src/revparse.c
index 8a22a04..e8cc32a 100644
--- a/src/revparse.c
+++ b/src/revparse.c
@@ -17,7 +17,7 @@
 static int disambiguate_refname(git_reference **out, git_repository *repo, const char *refname)
 {
 	int error = 0, i;
-	bool fallbackmode = true;
+	bool fallbackmode = true, foundvalid = false;
 	git_reference *ref;
 	git_buf refnamebuf = GIT_BUF_INIT, name = GIT_BUF_INIT;
 
@@ -49,6 +49,7 @@ static int disambiguate_refname(git_reference **out, git_repository *repo, const
 			error = GIT_EINVALIDSPEC;
 			continue;
 		}
+		foundvalid = true;
 
 		error = git_reference_lookup_resolved(&ref, repo, git_buf_cstr(&refnamebuf), -1);
 
@@ -63,6 +64,12 @@ static int disambiguate_refname(git_reference **out, git_repository *repo, const
 	}
 
 cleanup:
+	if (error && !foundvalid) {
+		/* never found a valid reference name */
+		giterr_set(GITERR_REFERENCE,
+			"Could not use '%s' as valid reference name", git_buf_cstr(&name));
+	}
+
 	git_buf_free(&name);
 	git_buf_free(&refnamebuf);
 	return error;