Fix filename verification when in a subdirectory

When we are in a subdirectory of a git archive, we need to take the prefix
of that subdirectory into accoung when we verify filename arguments.

Noted by Matthias Lederhofer

This also uses the improved error reporting for all the other git commands
that use the revision parsing interfaces, not just git-rev-parse. Also, it
makes the error reporting for mixed filenames and argument flags clearer
(you cannot put flags after the start of the pathname list).

[jc: with fix to a trivial typo noticed by Timo Hirvonen]

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
Linus Torvalds
2006-04-26 10:15:54 -07:00
committed by Junio C Hamano
parent b176e6ba5b
commit e23d0b4a4a
4 changed files with 29 additions and 18 deletions

View File

@ -160,14 +160,6 @@ 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;
@ -177,14 +169,12 @@ int main(int argc, char **argv)
git_config(git_default_config);
for (i = 1; i < argc; i++) {
struct stat st;
char *arg = argv[i];
char *dotdot;
if (as_is) {
if (show_file(arg) && as_is < 2)
if (lstat(arg, &st) < 0)
die_badfile(arg);
verify_filename(prefix, arg);
continue;
}
if (!strcmp(arg,"-n")) {
@ -350,8 +340,7 @@ int main(int argc, char **argv)
continue;
if (verify)
die("Needed a single revision");
if (lstat(arg, &st) < 0)
die_badfile(arg);
verify_filename(prefix, arg);
}
show_default();
if (verify && revs_count != 1)