All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] git.c: Re-introduce sane error messages on missing commands.
@ 2006-06-27  8:28 Andreas Ericsson
  2006-06-27 22:57 ` Junio C Hamano
  0 siblings, 1 reply; 9+ messages in thread
From: Andreas Ericsson @ 2006-06-27  8:28 UTC (permalink / raw)
  To: git

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

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2006-06-28 14:59 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-27  8:28 [PATCH] git.c: Re-introduce sane error messages on missing commands Andreas Ericsson
2006-06-27 22:57 ` Junio C Hamano
2006-06-28  8:13   ` Andreas Ericsson
2006-06-28  9:21     ` Johannes Schindelin
2006-06-28  9:53       ` Junio C Hamano
2006-06-28 10:45         ` Johannes Schindelin
2006-06-28 11:53           ` Andreas Ericsson
2006-06-28 12:00           ` Marco Roeland
2006-06-28 14:59             ` Christopher Faylor

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.