Skip to content

Commit ec0603e

Browse files
committed
Teach read-tree 2-way merge to ignore intermediate symlinks
Earlier in 16a4c61, we taught "read-tree -m -u" not to be confused when switching from a branch that has a path frotz/filfre to another branch that has a symlink frotz that points at xyzzy/ directory. The fix was incomplete in that it was still confused when coming back (i.e. switching from a branch with frotz -> xyzzy/ to another branch with frotz/filfre). This fix is rather expensive in that for a path that is created we would need to see if any of the leading component of that path exists as a symbolic link in the filesystem (in which case, we know that path itself does not exist, and the fact we already decided to check it out tells us that in the index we already know that symbolic link is going away as there is no D/F conflict). Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1b2782a commit ec0603e

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

t/t2007-checkout-symlink.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2007 Junio C Hamano
4+
5+
test_description='git checkout to switch between branches with symlink<->dir'
6+
7+
. ./test-lib.sh
8+
9+
test_expect_success setup '
10+
11+
mkdir frotz &&
12+
echo hello >frotz/filfre &&
13+
git add frotz/filfre &&
14+
test_tick &&
15+
git commit -m "master has file frotz/filfre" &&
16+
17+
git branch side &&
18+
19+
echo goodbye >nitfol &&
20+
git add nitfol
21+
test_tick &&
22+
git commit -m "master adds file nitfol" &&
23+
24+
git checkout side &&
25+
26+
git rm --cached frotz/filfre &&
27+
mv frotz xyzzy &&
28+
ln -s xyzzy frotz &&
29+
git add xyzzy/filfre frotz &&
30+
test_tick &&
31+
git commit -m "side moves frotz/ to xyzzy/ and adds frotz->xyzzy/"
32+
33+
'
34+
35+
test_expect_success 'switch from symlink to dir' '
36+
37+
git checkout master
38+
39+
'
40+
41+
rm -fr frotz xyzzy nitfol &&
42+
git checkout -f master || exit
43+
44+
test_expect_success 'switch from dir to symlink' '
45+
46+
git checkout side
47+
48+
'
49+
50+
test_done

unpack-trees.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,9 @@ static void verify_absent(const char *path, const char *action,
495495
if (o->index_only || o->reset || !o->update)
496496
return;
497497

498+
if (has_symlink_leading_path(path, NULL))
499+
return;
500+
498501
if (!lstat(path, &st)) {
499502
int cnt;
500503

0 commit comments

Comments
 (0)