{"thread":{"id":"3960","subject":"[PATCH] rev-parse: better error message for ambiguous arguments","startedAt":"2006-04-25T00:00:03Z","lastAt":"2006-04-25T00:00:03Z","messageCount":1,"participants":["Paul Mackerras"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"19067","messageId":"17485.26243.520304.408507@cargo.ozlabs.ibm.com","threadId":"3960","inReplyTo":null,"subject":"[PATCH] rev-parse: better error message for ambiguous arguments","fromName":"Paul Mackerras","fromEmail":"paulus@samba.org","sentAt":"2006-04-25T00:00:03Z","receivedAt":"2006-04-25T00:00:03Z","isPatch":true,"sender":{"key":"paulus@samba.org","avatar":"https://avatars.githubusercontent.com/u/1606439?v=4"},"body":"Currently, if git-rev-parse encounters an argument that is neither a\nrecognizable revision name nor the name of an existing file or\ndirectory, and it hasn't encountered a \"--\" argument, it prints an\nerror message saying \"No such file or directory\".  This can be\nconfusing for users, including users of programs such as gitk that\nuse git-rev-parse, who may then think that they can't ask about the\nhistory of files that no longer exist.\n\nThis makes it print a better error message, one that points out the\nambiguity and tells the user what to do to fix it.\n\nSigned-off-by: Paul Mackerras <paulus@samba.org>\n---\ndiff --git a/rev-parse.c b/rev-parse.c\nindex e956cd5..7f66ae2 100644\n--- a/rev-parse.c\n+++ b/rev-parse.c\n@@ -160,6 +160,14 @@ static int show_file(const char *arg)\n \treturn 0;\n }\n \n+static void die_badfile(const char *arg)\n+{\n+\tif (errno != ENOENT)\n+\t\tdie(\"'%s': %s\", arg, strerror(errno));\n+\tdie(\"'%s' is ambiguous - revision name or file/directory name?\\n\"\n+\t    \"Please put '--' before the list of filenames.\", arg);\n+}\n+\n int main(int argc, char **argv)\n {\n \tint i, as_is = 0, verify = 0;\n@@ -176,7 +184,7 @@ int main(int argc, char **argv)\n \t\tif (as_is) {\n \t\t\tif (show_file(arg) && as_is < 2)\n \t\t\t\tif (lstat(arg, &st) < 0)\n-\t\t\t\t\tdie(\"'%s': %s\", arg, strerror(errno));\n+\t\t\t\t\tdie_badfile(arg);\n \t\t\tcontinue;\n \t\t}\n \t\tif (!strcmp(arg,\"-n\")) {\n@@ -343,7 +351,7 @@ int main(int argc, char **argv)\n \t\tif (verify)\n \t\t\tdie(\"Needed a single revision\");\n \t\tif (lstat(arg, &st) < 0)\n-\t\t\tdie(\"'%s': %s\", arg, strerror(errno));\n+\t\t\tdie_badfile(arg);\n \t}\n \tshow_default();\n \tif (verify && revs_count != 1)\n"}]}