Skip to content

Commit f02033f

Browse files
committed
t3004: add test for ls-files on symlinks via absolute paths
When symlinks in the working tree are manipulated using the absolute path, git dereferences them, and tries to manipulate the link target instead. This causes most high-level functions to misbehave when acting on symlinks given via absolute paths. For example $ git add /dir/repo/symlink attempts to add the target of the symlink rather than the symlink itself, which is usually not what the user intends to do. This is a regression introduced by 18e051a: setup: translate symlinks in filename when using absolute paths (which did not take symlinks inside the work tree into consideration). Add a known-breakage test using the ls-files function, checking both if the symlink leads to a target in the same directory, and a target in the above directory. Signed-off-by: Martin Erik Werner <[email protected]> Tested-by: Martin Erik Werner <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ac93028 commit f02033f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

t/t3004-ls-files-basic.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,21 @@ test_expect_success 'ls-files -h in corrupt repository' '
3636
test_i18ngrep "[Uu]sage: git ls-files " broken/usage
3737
'
3838

39+
test_expect_failure SYMLINKS 'ls-files with absolute paths to symlinks' '
40+
mkdir subs &&
41+
ln -s nosuch link &&
42+
ln -s ../nosuch subs/link &&
43+
git add link subs/link &&
44+
git ls-files -s link subs/link >expect &&
45+
git ls-files -s "$(pwd)/link" "$(pwd)/subs/link" >actual &&
46+
test_cmp expect actual &&
47+
48+
(
49+
cd subs &&
50+
git ls-files -s link >../expect &&
51+
git ls-files -s "$(pwd)/link" >../actual
52+
) &&
53+
test_cmp expect actual
54+
'
55+
3956
test_done

0 commit comments

Comments
 (0)