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>
Clemens Buchacher committed
Feb 20, 2011 at 13:13 UTC
1d718a5108f905e3c64f9fa791e67a52bd926457
2 files changed
+12
-4
symlinks.c
+1
-1
@@ -223,7 +223,7 @@ int check_leading_path(const char *name, int len)
223
int flags;
224
int match_len = lstat_cache_matchlen(cache, name, len, &flags,
225
FL_SYMLINK|FL_NOENT|FL_DIR, USE_ONLY_LSTAT);
226
- if (flags & (FL_SYMLINK|FL_NOENT))
226
+ if (flags & FL_NOENT)
227
return 0;
228
else if (flags & FL_DIR)
229
return -1;
t/t6035-merge-dir-to-symlink.sh
+11
-3
@@ -17,13 +17,21 @@ test_expect_success SYMLINKS 'create a commit where dir a/b changed to symlink'
17
git commit -m "dir to symlink"
18
'
19
20
-test_expect_success SYMLINKS 'keep a/b-2/c/d across checkout' '
20
+test_expect_success SYMLINKS 'checkout does not clobber untracked symlink' '
21
git checkout HEAD^0 &&
22
git reset --hard master &&
23
git rm --cached a/b &&
24
git commit -m "untracked symlink remains" &&
25
- git checkout start^0 &&
26
- test -f a/b-2/c/d
25
+ test_must_fail git checkout start^0
26
+'
27
+
28
+test_expect_success SYMLINKS 'a/b-2/c/d is kept when clobbering symlink b' '
29
+ git checkout HEAD^0 &&
30
+ git reset --hard master &&
31
+ git rm --cached a/b &&
32
+ git commit -m "untracked symlink remains" &&
33
+ git checkout -f start^0 &&
34
+ test -f a/b-2/c/d
35
'
36
37
test_expect_success SYMLINKS 'checkout should not have deleted a/b-2/c/d' '