git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Fix error handling for nonexistent names

From
Linus Torvalds <torvalds@osdl.org>
Date
Mar 27, 2006, 00:28 UTC
Message-ID
<Pine.LNX.4.64.0603261620130.15714@g5.osdl.org>
[ This is an expanded version of a patch I sent out earlier: the 
  "rev-parse.c" part of it is identical to the earlier version, the 
  revision.c thing is new ]

When passing in a pathname pattern without the "--" separator on the command line, we verify that the pathnames in question exist. However, there were two bugs in that verification:

 - git-rev-parse would only check the first pathname, and silently allow 
   any invalid subsequent pathname, whether it existed or not (which 
   defeats the purpose of the check, and is also inconsistent with what 
   git-rev-list actually does)
 - git-rev-list (and "git log" etc) would check each filename, but if the 
   check failed, it would print the error using the first one, ie:
	[torvalds@g5 git]$ git log Makefile bad-file
	fatal: 'Makefile': No such file or directory
   instead of saying that it's 'bad-file' that doesn't exist.
This fixes both bugs.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---
diff --git a/rev-parse.c b/rev-parse.c
index 19a5ef7..8ca1c69 100644
--- a/rev-parse.c
+++ b/rev-parse.c
@@ -174,7 +174,9 @@ int main(int argc, char **argv)
 		char *dotdot;
 	
 		if (as_is) {
-			show_file(arg);
+			if (show_file(arg) && as_is < 2)
+				if (lstat(arg, &st) < 0)
+					die("'%s': %s", arg, strerror(errno));
 			continue;
 		}
 		if (!strcmp(arg,"-n")) {
@@ -194,7 +196,7 @@ int main(int argc, char **argv)
 
 		if (*arg == '-') {
 			if (!strcmp(arg, "--")) {
-				as_is = 1;
+				as_is = 2;
 				/* Pass on the "--" if we show anything but files.. */
 				if (filter & (DO_FLAGS | DO_REVS))
 					show_file(arg);
diff --git a/revision.c b/revision.c
index 12cd052..d67718c 100644
--- a/revision.c
+++ b/revision.c
@@ -649,7 +649,7 @@ int setup_revisions(int argc, const char
 			/* If we didn't have a "--", all filenames must exist */
 			for (j = i; j < argc; j++) {
 				if (lstat(argv[j], &st) < 0)
-					die("'%s': %s", arg, strerror(errno));
+					die("'%s': %s", argv[j], strerror(errno));
 			}
 			revs->prune_data = get_pathspec(revs->prefix, argv + i);
 			break;
Message 1 of 1 in “Fix error handling for nonexistent names”
  1. Linus TorvaldsMar 27, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.