{"thread":{"id":"20165","subject":"Bad DWIM response when git gui cannot start","startedAt":"2009-07-20T12:11:21Z","lastAt":"2009-07-20T15:12:17Z","messageCount":4,"participants":["Peter Krefting","Michele Ballabio","Thomas Rast","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"118307","messageId":"alpine.DEB.2.00.0907201309150.5423@ds9.cixit.se","threadId":"20165","inReplyTo":null,"subject":"Bad DWIM response when git gui cannot start","fromName":"Peter Krefting","fromEmail":"peter@softwolves.pp.se","sentAt":"2009-07-20T12:11:21Z","receivedAt":"2009-07-20T12:11:21Z","isPatch":false,"sender":{"key":"peter@softwolves.pp.se","avatar":"https://avatars.githubusercontent.com/u/990764?v=4"},"body":"If git cannot start one of the external commands (at least some of them), \nthe DWIM engine is a bit flaky:\n\n   $ git citool\n   /usr/local/libexec/git-core/git-citool: line 10: exec: wish: not found\n   git: 'citool' is not a git-command. See 'git --help'.\n\n   Did you mean this?\n       citool\n\n   $ git gui\n   /usr/local/libexec/git-core/git-gui: line 10: exec: wish: not found\n   git: 'gui' is not a git-command. See 'git --help'.\n\n   Did you mean this?\n       gui\n\n-- \n\\\\// Peter - http://www.softwolves.pp.se/\n"},{"id":"118310","messageId":"200907201545.06030.barra_cuda@katamail.com","threadId":"20165","inReplyTo":"alpine.DEB.2.00.0907201309150.5423@ds9.cixit.se","subject":"[PATCH] help.c: don't blame an user's typo when the system is at fault","fromName":"Michele Ballabio","fromEmail":"barra_cuda@katamail.com","sentAt":"2009-07-20T13:45:05Z","receivedAt":"2009-07-20T13:45:05Z","isPatch":true,"sender":{"key":"barra_cuda@katamail.com","avatar":"https://avatars.githubusercontent.com/u/16371673?v=4"},"body":"As reported by Peter Krefting:\n\n  If git cannot start one of the external commands (at least some of them),\n  the DWIM engine is a bit flaky:\n\n     $ git citool\n     /usr/local/libexec/git-core/git-citool: line 10: exec: wish: not found\n     git: 'citool' is not a git-command. See 'git --help'.\n\n     Did you mean this?\n         citool\n\nNow we check whether the best bet found by levenshtein() differs from\nthe command line or not before proceeding.\n\nThe new error is:\n\n$ git citool\n/usr/local/libexec/git-core/git-citool: line 10: exec: wish: not found\nfatal: Failed to run command 'citool': No such file or directory\n\nSigned-off-by: Michele Ballabio <barra_cuda@katamail.com>\n---\n\nIs the call to strerror() useless anyway?\n\n help.c |    3 +++\n 1 files changed, 3 insertions(+), 0 deletions(-)\n\ndiff --git a/help.c b/help.c\nindex fd87bb5..eec62a3 100644\n--- a/help.c\n+++ b/help.c\n@@ -325,6 +325,9 @@ const char *help_unknown_cmd(const char *cmd)\n \n \tif (!main_cmds.cnt)\n \t\tdie (\"Uh oh. Your system reports no Git commands at all.\");\n+\tif (!strcmp(cmd, main_cmds.names[0]->name))\n+\t\tdie(\"Failed to run command '%s': %s\\n\",\n+\t\t\tcmd, strerror(errno));\n \n \tbest_similarity = main_cmds.names[0]->len;\n \tn = 1;\n-- \n1.6.3.1.17.g076c3\n"},{"id":"118314","messageId":"200907201617.48168.trast@student.ethz.ch","threadId":"20165","inReplyTo":"200907201545.06030.barra_cuda@katamail.com","subject":"Re: [PATCH] help.c: don't blame an user's typo when the system is at fault","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2009-07-20T14:17:47Z","receivedAt":"2009-07-20T14:17:47Z","isPatch":true,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Michele Ballabio wrote:\n> Is the call to strerror() useless anyway?\n[...]\n> +\tif (!strcmp(cmd, main_cmds.names[0]->name))\n> +\t\tdie(\"Failed to run command '%s': %s\\n\",\n> +\t\t\tcmd, strerror(errno));\n\nThe invocation of help_unknown_cmd comes from\n\n\twhile (1) {\n\t\t// ...\n\t\twas_alias = run_argv(&argc, &argv);\n\t\tif (errno != ENOENT)\n\t\t\tbreak;\n\t\t// ... side branch with an exit() ...\n\t\tif (!done_help) {\n\t\t\tcmd = argv[0] = help_unknown_cmd(cmd);\n\nso errno is always ENOENT when help_unknown_cmd() is called.\n(Furthermore, the function itself uses git_config() and\nload_command_list(), both of which _probably_ clobber errno, I don't\nreally have the time for an in-depth check.)\n\nIt also seems that the 'errno != ENOENT' check was intended to catch\nthe case where the command failed for any reason other than that it\ndoes not exist, but this collides with the kernel reporting ENOENT if\nthe _interpreter_ does not exist.  Perhaps run_argv should\ndifferentiate the case where a command executable exists but cannot be\nrun?\n\n\n[I started writing a reply because I wanted to ask for a conversion to\ndie_errno() in the spirit of d824cbb (Convert existing die(...,\nstrerror(errno)) to die_errno(), 2009-06-27).  Please keep that in\nmind if you put in another die() that mentions errno.]\n\n-- \nThomas Rast\ntrast@{inf,student}.ethz.ch\n"},{"id":"118318","messageId":"20090720151217.GA5347@coredump.intra.peff.net","threadId":"20165","inReplyTo":"200907201617.48168.trast@student.ethz.ch","subject":"Re: [PATCH] help.c: don't blame an user's typo when the system is at fault","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-07-20T15:12:17Z","receivedAt":"2009-07-20T15:12:17Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Jul 20, 2009 at 04:17:47PM +0200, Thomas Rast wrote:\n\n> The invocation of help_unknown_cmd comes from\n> \n> \twhile (1) {\n> \t\t// ...\n> \t\twas_alias = run_argv(&argc, &argv);\n> \t\tif (errno != ENOENT)\n> \t\t\tbreak;\n> \t\t// ... side branch with an exit() ...\n> \t\tif (!done_help) {\n> \t\t\tcmd = argv[0] = help_unknown_cmd(cmd);\n> \n> so errno is always ENOENT when help_unknown_cmd() is called.\n> (Furthermore, the function itself uses git_config() and\n> load_command_list(), both of which _probably_ clobber errno, I don't\n> really have the time for an in-depth check.)\n> \n> It also seems that the 'errno != ENOENT' check was intended to catch\n> the case where the command failed for any reason other than that it\n> does not exist, but this collides with the kernel reporting ENOENT if\n> the _interpreter_ does not exist.  Perhaps run_argv should\n> differentiate the case where a command executable exists but cannot be\n> run?\n\nYes, I think double-checking the suggested commands list is only half of\nit; it still says \"citool is not a git command\" which is wrong. Getting\nit totally right means differentiating the two ENOENT cases, which I\nthink would require searching the PATH.\n\nSomething like the patch below should work, though I didn't think\nterribly long about it, so there might be a corner case that isn't\ncovered, or some easier helper functions for accomplishing this.\n\n---\ndiff --git a/git.c b/git.c\nindex 5da6c65..4e44c98 100644\n--- a/git.c\n+++ b/git.c\n@@ -3,6 +3,7 @@\n #include \"cache.h\"\n #include \"quote.h\"\n #include \"run-command.h\"\n+#include \"help.h\"\n \n const char git_usage_string[] =\n \t\"git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path] [-p|--paginate|--no-pager] [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE] [--help] COMMAND [ARGS]\";\n@@ -449,6 +450,16 @@ static int run_argv(int *argcp, const char ***argv)\n \treturn done_alias;\n }\n \n+static int command_exists(const char *s)\n+{\n+\tstatic struct cmdnames main_cmds, other_cmds;\n+\tstatic int loaded;\n+\tif (!loaded) {\n+\t\tload_command_list(\"git-\", &main_cmds, &other_cmds);\n+\t\tloaded = 1;\n+\t}\n+\treturn is_in_cmdlist(&main_cmds, s) || is_in_cmdlist(&other_cmds, s);\n+}\n \n int main(int argc, const char **argv)\n {\n@@ -504,7 +515,7 @@ int main(int argc, const char **argv)\n \t\tstatic int done_help = 0;\n \t\tstatic int was_alias = 0;\n \t\twas_alias = run_argv(&argc, &argv);\n-\t\tif (errno != ENOENT)\n+\t\tif (errno != ENOENT || command_exists(argv[0]))\n \t\t\tbreak;\n \t\tif (was_alias) {\n \t\t\tfprintf(stderr, \"Expansion of alias '%s' failed; \"\n"}]}