mirror of
https://github.com/git/git.git
synced 2024-11-24 02:17:02 +08:00
add: refuse to add working tree items beyond symlinks
This is the same fix for the issue of adding "sym/path" when "sym" is a symblic link that points at a directory "dir" with "path" in it. Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
806d13b1cc
commit
725b06050a
@ -153,6 +153,16 @@ static const char **validate_pathspec(int argc, const char **argv, const char *p
|
||||
{
|
||||
const char **pathspec = get_pathspec(prefix, argv);
|
||||
|
||||
if (pathspec) {
|
||||
const char **p;
|
||||
for (p = pathspec; *p; p++) {
|
||||
if (has_symlink_leading_path(strlen(*p), *p)) {
|
||||
int len = prefix ? strlen(prefix) : 0;
|
||||
die("'%s' is beyond a symbolic link", *p + len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pathspec;
|
||||
}
|
||||
|
||||
@ -278,7 +288,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
|
||||
fprintf(stderr, "Maybe you wanted to say 'git add .'?\n");
|
||||
return 0;
|
||||
}
|
||||
pathspec = get_pathspec(prefix, argv);
|
||||
pathspec = validate_pathspec(argc, argv, prefix);
|
||||
|
||||
/*
|
||||
* If we are adding new files, we need to scan the working
|
||||
|
6
dir.c
6
dir.c
@ -727,8 +727,12 @@ static void free_simplify(struct path_simplify *simplify)
|
||||
|
||||
int read_directory(struct dir_struct *dir, const char *path, const char *base, int baselen, const char **pathspec)
|
||||
{
|
||||
struct path_simplify *simplify = create_simplify(pathspec);
|
||||
struct path_simplify *simplify;
|
||||
|
||||
if (has_symlink_leading_path(strlen(path), path))
|
||||
return dir->nr;
|
||||
|
||||
simplify = create_simplify(pathspec);
|
||||
read_directory_recursive(dir, path, base, baselen, 0, simplify);
|
||||
free_simplify(simplify);
|
||||
qsort(dir->entries, dir->nr, sizeof(struct dir_entry *), cmp_name);
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
test_description='update-index refuses to add beyond symlinks'
|
||||
test_description='update-index and add refuse to add beyond symlinks'
|
||||
|
||||
. ./test-lib.sh
|
||||
|
||||
@ -17,4 +17,9 @@ test_expect_success 'update-index --add beyond symlinks' '
|
||||
! ( git ls-files | grep c/d )
|
||||
'
|
||||
|
||||
test_expect_success 'add beyond symlinks' '
|
||||
test_must_fail git add c/d &&
|
||||
! ( git ls-files | grep c/d )
|
||||
'
|
||||
|
||||
test_done
|
||||
|
Loading…
Reference in New Issue
Block a user