From fb18a2edf7f3d1585b6330b7dde110b992d3b97c Mon Sep 17 00:00:00 2001
From: Linus Torvalds <torvalds@osdl.org>
Date: Sun, 26 Mar 2006 16:28:20 -0800
Subject: Fix error handling for nonexistent names

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, i.e.:

	[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>
Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 rev-parse.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

(limited to 'rev-parse.c')

diff --git a/rev-parse.c b/rev-parse.c
index 19a5ef7f4..f176c56f7 100644
--- a/rev-parse.c
+++ b/rev-parse.c
@@ -172,9 +172,11 @@ int main(int argc, char **argv)
 		struct stat st;
 		char *arg = argv[i];
 		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);
-- 
cgit v1.2.1