git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] git.c: Re-introduce sane error messages on missing commands.

From
Andreas Ericsson <ae@op5.se>
Date
Jun 27, 2006, 08:28 UTC
Message-ID
<20060627083508.E912A5BBAB@nox.op5.se>
Somewhere in the alias handling git turned hostile on fat fingers:
	$ git showbranch
	Failed to run command '': Is a directory
This patch fixes that by doing 2 things:
 * The variable git_command[MAX_PATH + 1] is now retired from
   git.c:main() where it was never set. Instead the variable "cmd"
   is used for all error messages.
 * The introduction of the "exec_errno" variable which preserves the
   errno number from the execve() attempt. Later "why did it fail"
   tests evaluate exec_errno, which gives the correct error message
   along with the brief command-list (telling me I missed the dash in
   "show-branch").

It's possible that alias handling can fail and set errno to something proper, making this change less sane than I think, but handle_alias() seems to take care of its own error-handling so it shouldn't matter.

Signed-off-by: Andreas Ericsson <ae@op5.se>
---
 git.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/git.c b/git.c
index 94e9a4a..b04424f 100644
--- a/git.c
+++ b/git.c
@@ -206,9 +206,8 @@ int main(int argc, const char **argv, ch
 {
 	const char *cmd = argv[0];
 	char *slash = strrchr(cmd, '/');
-	char git_command[PATH_MAX + 1];
 	const char *exec_path = NULL;
-	int done_alias = 0;
+	int exec_errno = 0, done_alias = 0;
 
 	/*
 	 * Take the basename of argv[0] as the command
@@ -300,6 +299,9 @@ int main(int argc, const char **argv, ch
 		/* .. then try the external ones */
 		execv_git_cmd(argv);
 
+		/* if it's not an alias, the execve() errno is what we want */
+		exec_errno = errno;
+
 		/* It could be an alias -- this works around the insanity
 		 * of overriding "git log" with "git show" by having
 		 * alias.log = show
@@ -309,11 +311,11 @@ int main(int argc, const char **argv, ch
 		done_alias = 1;
 	}
 
-	if (errno == ENOENT)
+	if (exec_errno == ENOENT)
 		cmd_usage(0, exec_path, "'%s' is not a git-command", cmd);
 
 	fprintf(stderr, "Failed to run command '%s': %s\n",
-		git_command, strerror(errno));
+		cmd, strerror(exec_errno));
 
 	return 1;
 }
-- 
1.4.1.rc1.g1ef9
Next: Junio C Hamano
Message 1 of 9 in “git.c: Re-introduce sane error messages on missing commands.”
  1. git.c: Re-introduce sane error messages on missing commands.Andreas Ericsson, Jun 27, 2006
  2. Junio C HamanoJun 27, 2006
  3. Andreas EricssonJun 28, 2006
  4. Johannes SchindelinJun 28, 2006
  5. Junio C HamanoJun 28, 2006
  6. Johannes SchindelinJun 28, 2006
  7. Andreas EricssonJun 28, 2006
  8. Marco RoelandJun 28, 2006
  9. Christopher FaylorJun 28, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.