@matheusbsbs / matheus-bagliano / commits / fb18a2edf7
Fork 0

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>

Linus Torvalds committed Mar 26, 2006 at 16:28 UTC fb18a2edf7f3d1585b6330b7dde110b992d3b97c
2 files changed +6 -4
rev-parse.c
+5 -3
@@ -172,9 +172,11 @@ int main(int argc, char **argv)
172 struct stat st;
173 char *arg = argv[i];
174 char *dotdot;
175 -
175 +
176 if (as_is) {
177 - show_file(arg);
177 + if (show_file(arg) && as_is < 2)
178 + if (lstat(arg, &st) < 0)
179 + die("'%s': %s", arg, strerror(errno));
180 continue;
181 }
182 if (!strcmp(arg,"-n")) {
@@ -194,7 +196,7 @@ int main(int argc, char **argv)
196
197 if (*arg == '-') {
198 if (!strcmp(arg, "--")) {
197 - as_is = 1;
199 + as_is = 2;
200 /* Pass on the "--" if we show anything but files.. */
201 if (filter & (DO_FLAGS | DO_REVS))
202 show_file(arg);
revision.c
+1 -1
@@ -649,7 +649,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
649 /* If we didn't have a "--", all filenames must exist */
650 for (j = i; j < argc; j++) {
651 if (lstat(argv[j], &st) < 0)
652 - die("'%s': %s", arg, strerror(errno));
652 + die("'%s': %s", argv[j], strerror(errno));
653 }
654 revs->prune_data = get_pathspec(revs->prefix, argv + i);
655 break;