Skip to content

Commit 1d718a5

Browse files
Clemens Buchachergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2fe26b7 commit 1d718a5

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

symlinks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ int check_leading_path(const char *name, int len)
223223
int flags;
224224
int match_len = lstat_cache_matchlen(cache, name, len, &flags,
225225
FL_SYMLINK|FL_NOENT|FL_DIR, USE_ONLY_LSTAT);
226-
if (flags & (FL_SYMLINK|FL_NOENT))
226+
if (flags & FL_NOENT)
227227
return 0;
228228
else if (flags & FL_DIR)
229229
return -1;

t/t6035-merge-dir-to-symlink.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,21 @@ test_expect_success SYMLINKS 'create a commit where dir a/b changed to symlink'
1717
git commit -m "dir to symlink"
1818
'
1919

20-
test_expect_success SYMLINKS 'keep a/b-2/c/d across checkout' '
20+
test_expect_success SYMLINKS 'checkout does not clobber untracked symlink' '
2121
git checkout HEAD^0 &&
2222
git reset --hard master &&
2323
git rm --cached a/b &&
2424
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
2735
'
2836

2937
test_expect_success SYMLINKS 'checkout should not have deleted a/b-2/c/d' '

0 commit comments

Comments
 (0)