threads / patch / 3960

patchrev-parse: better error message for ambiguous arguments

Subject: [PATCH] rev-parse: better error message for ambiguous arguments

## tl;dr

One message between Apr 25, 2006 and Apr 25, 2006. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Paul Mackerras· Apr 25, 2006, 00:00 UTC · lore

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>
---
Show changes to rev-parse.c +10 −2
diff --git a/rev-parse.c b/rev-parse.c
index e956cd5..7f66ae2 100644
--- a/rev-parse.c
+++ b/rev-parse.c
@@ -160,6 +160,14 @@ static int show_file(const char *arg)
 	return 0;
 }
 
+static void die_badfile(const char *arg)
+{
+	if (errno != ENOENT)
+		die("'%s': %s", arg, strerror(errno));
+	die("'%s' is ambiguous - revision name or file/directory name?\n"
+	    "Please put '--' before the list of filenames.", arg);
+}
+
 int main(int argc, char **argv)
 {
 	int i, as_is = 0, verify = 0;
@@ -176,7 +184,7 @@ int main(int argc, char **argv)
 		if (as_is) {
 			if (show_file(arg) && as_is < 2)
 				if (lstat(arg, &st) < 0)
-					die("'%s': %s", arg, strerror(errno));
+					die_badfile(arg);
 			continue;
 		}
 		if (!strcmp(arg,"-n")) {
@@ -343,7 +351,7 @@ int main(int argc, char **argv)
 		if (verify)
 			die("Needed a single revision");
 		if (lstat(arg, &st) < 0)
-			die("'%s': %s", arg, strerror(errno));
+			die_badfile(arg);
 	}
 	show_default();
 	if (verify && revs_count != 1)

← back to recent threads