summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: fba5279)
raw | patch | inline | side by side (parent: fba5279)
author | Junio C Hamano <gitster@pobox.com> | |
Mon, 4 Aug 2008 07:51:42 +0000 (00:51 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Tue, 5 Aug 2008 06:31:23 +0000 (23:31 -0700) |
When "sym" is a symbolic link that is inside the working tree, and it
points at a directory "dir" that has "path" in it, "update-index --add
sym/path" used to mistakenly add "sym/path" as if "sym" were a normal
directory.
"git apply", "git diff" and "git merge" have been taught about this issue
some time ago, but "update-index" and "add" have been left ignorant for
too long.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
points at a directory "dir" that has "path" in it, "update-index --add
sym/path" used to mistakenly add "sym/path" as if "sym" were a normal
directory.
"git apply", "git diff" and "git merge" have been taught about this issue
some time ago, but "update-index" and "add" have been left ignorant for
too long.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-update-index.c | patch | blob | history | |
t/t0055-beyond-symlinks.sh | [new file with mode: 0755] | patch | blob |
diff --git a/builtin-update-index.c b/builtin-update-index.c
index 38eb53ccba2b97a0fccf50d6ba0b7424fe2d1bcb..434cb8e4a00565c53587d89dd259ae63bc133de7 100644 (file)
--- a/builtin-update-index.c
+++ b/builtin-update-index.c
int len;
struct stat st;
+ len = strlen(path);
+ if (has_symlink_leading_path(len, path))
+ return error("'%s' is beyond a symbolic link", path);
+
/*
* First things first: get the stat information, to decide
* what to do about the pathname!
if (lstat(path, &st) < 0)
return process_lstat_error(path, errno);
- len = strlen(path);
if (S_ISDIR(st.st_mode))
return process_directory(path, len, &st);
diff --git a/t/t0055-beyond-symlinks.sh b/t/t0055-beyond-symlinks.sh
--- /dev/null
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+test_description='update-index refuses to add beyond symlinks'
+
+. ./test-lib.sh
+
+test_expect_success setup '
+ >a &&
+ mkdir b &&
+ ln -s b c &&
+ >c/d &&
+ git update-index --add a b/d
+'
+
+test_expect_success 'update-index --add beyond symlinks' '
+ test_must_fail git update-index --add c/d &&
+ ! ( git ls-files | grep c/d )
+'
+
+test_done