@matheusbsbs / matheus-bagliano / commits / 3e1a70d925
Fork 0

rev-parse: better error message for ambiguous arguments

Currently, if git-rev-parse encounters an argument that is neither a recognizable revision name nor the name of an existing file or directory, and it hasn't encountered a "--" argument, it prints an error message saying "No such file or directory". This can be confusing for users, including users of programs such as gitk that use git-rev-parse, who may then think that they can't ask about the history of files that no longer exist. This makes it print a better error message, one that points out the ambiguity and tells the user what to do to fix it. Signed-off-by: Paul Mackerras <paulus@samba.org>

Paul Mackerras committed Apr 25, 2006 at 10:00 UTC 3e1a70d925b46b9eac1ae523589298ddb6e295af
1 file changed +10 -2
rev-parse.c
+10 -2
@@ -160,6 +160,14 @@ static int show_file(const char *arg)
160 return 0;
161 }
162
163 +static void die_badfile(const char *arg)
164 +{
165 + if (errno != ENOENT)
166 + die("'%s': %s", arg, strerror(errno));
167 + die("'%s' is ambiguous - revision name or file/directory name?\n"
168 + "Please put '--' before the list of filenames.", arg);
169 +}
170 +
171 int main(int argc, char **argv)
172 {
173 int i, as_is = 0, verify = 0;
@@ -176,7 +184,7 @@ int main(int argc, char **argv)
184 if (as_is) {
185 if (show_file(arg) && as_is < 2)
186 if (lstat(arg, &st) < 0)
179 - die("'%s': %s", arg, strerror(errno));
187 + die_badfile(arg);
188 continue;
189 }
190 if (!strcmp(arg,"-n")) {
@@ -343,7 +351,7 @@ int main(int argc, char **argv)
351 if (verify)
352 die("Needed a single revision");
353 if (lstat(arg, &st) < 0)
346 - die("'%s': %s", arg, strerror(errno));
354 + die_badfile(arg);
355 }
356 show_default();
357 if (verify && revs_count != 1)