aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClemens Buchacher <drizzd@aon.at>2011-02-20 13:13:43 +0100
committerJunio C Hamano <gitster@pobox.com>2011-02-21 22:51:07 -0800
commit1d718a5108f905e3c64f9fa791e67a52bd926457 (patch)
tree9871ac56854e4a1e983e390cd2c9f3a24beb0921
parent2fe26b775cfa298a0b4bc3c53011ca6da7c6c298 (diff)
downloadgit-1d718a5108f905e3c64f9fa791e67a52bd926457.tar.gz
git-1d718a5108f905e3c64f9fa791e67a52bd926457.tar.xz
do not overwrite untracked symlinks
Git traditionally overwrites untracked symlinks silently. This will generally not cause massive data loss, but it is inconsistent with the behavior for regular files, which are not silently overwritten. With this change, git refuses to overwrite untracked symlinks by default. If the user really wants to overwrite the untracked symlink, he has git-clean and git-checkout -f at his disposal. Signed-off-by: Clemens Buchacher <drizzd@aon.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--symlinks.c2
-rwxr-xr-xt/t6035-merge-dir-to-symlink.sh14
2 files changed, 12 insertions, 4 deletions
diff --git a/symlinks.c b/symlinks.c
index 3cacebd91..034943bda 100644
--- a/symlinks.c
+++ b/symlinks.c
@@ -223,7 +223,7 @@ int check_leading_path(const char *name, int len)
int flags;
int match_len = lstat_cache_matchlen(cache, name, len, &flags,
FL_SYMLINK|FL_NOENT|FL_DIR, USE_ONLY_LSTAT);
- if (flags & (FL_SYMLINK|FL_NOENT))
+ if (flags & FL_NOENT)
return 0;
else if (flags & FL_DIR)
return -1;
diff --git a/t/t6035-merge-dir-to-symlink.sh b/t/t6035-merge-dir-to-symlink.sh
index 92e02d5d7..2599ae50e 100755
--- a/t/t6035-merge-dir-to-symlink.sh
+++ b/t/t6035-merge-dir-to-symlink.sh
@@ -17,13 +17,21 @@ test_expect_success SYMLINKS 'create a commit where dir a/b changed to symlink'
git commit -m "dir to symlink"
'
-test_expect_success SYMLINKS 'keep a/b-2/c/d across checkout' '
+test_expect_success SYMLINKS 'checkout does not clobber untracked symlink' '
git checkout HEAD^0 &&
git reset --hard master &&
git rm --cached a/b &&
git commit -m "untracked symlink remains" &&
- git checkout start^0 &&
- test -f a/b-2/c/d
+ test_must_fail git checkout start^0
+'
+
+test_expect_success SYMLINKS 'a/b-2/c/d is kept when clobbering symlink b' '
+ git checkout HEAD^0 &&
+ git reset --hard master &&
+ git rm --cached a/b &&
+ git commit -m "untracked symlink remains" &&
+ git checkout -f start^0 &&
+ test -f a/b-2/c/d
'
test_expect_success SYMLINKS 'checkout should not have deleted a/b-2/c/d' '