Skip to content

Commit 3bc5590

Browse files
piscisaureusdscho
authored andcommitted
Win32: symlink: add test for symlink attribute
To verify that the symlink is resolved correctly, we use the fact that `git.exe` is a native Win32 program, and that `git.exe config -f <path>` therefore uses the native symlink resolution. Signed-off-by: Bert Belder <bertbelder@gmail.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 51df38b commit 3bc5590

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

Diff for: t/meson.build

+1
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ integration_tests = [
276276
't2027-checkout-track.sh',
277277
't2030-unresolve-info.sh',
278278
't2031-checkout-long-paths.sh',
279+
't2040-checkout-symlink-attr.sh',
279280
't2050-git-dir-relative.sh',
280281
't2060-switch.sh',
281282
't2070-restore.sh',

Diff for: t/t2040-checkout-symlink-attr.sh

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/sh
2+
3+
test_description='checkout symlinks with `symlink` attribute on Windows
4+
5+
Ensures that Git for Windows creates symlinks of the right type,
6+
as specified by the `symlink` attribute in `.gitattributes`.'
7+
8+
# Tell MSYS to create native symlinks. Without this flag test-lib's
9+
# prerequisite detection for SYMLINKS doesn't detect the right thing.
10+
MSYS=winsymlinks:nativestrict && export MSYS
11+
12+
. ./test-lib.sh
13+
14+
if ! test_have_prereq MINGW,SYMLINKS
15+
then
16+
skip_all='skipping $0: MinGW-only test, which requires symlink support.'
17+
test_done
18+
fi
19+
20+
# Adds a symlink to the index without clobbering the work tree.
21+
cache_symlink () {
22+
sha=$(printf '%s' "$1" | git hash-object --stdin -w) &&
23+
git update-index --add --cacheinfo 120000,$sha,"$2"
24+
}
25+
26+
test_expect_success 'checkout symlinks with attr' '
27+
cache_symlink file1 file-link &&
28+
cache_symlink dir dir-link &&
29+
30+
printf "file-link symlink=file\ndir-link symlink=dir\n" >.gitattributes &&
31+
git add .gitattributes &&
32+
33+
git checkout . &&
34+
35+
mkdir dir &&
36+
echo "[a]b=c" >file1 &&
37+
echo "[x]y=z" >dir/file2 &&
38+
39+
# MSYS2 is very forgiving, it will resolve symlinks even if the
40+
# symlink type is incorrect. To make this test meaningful, try
41+
# them with a native, non-MSYS executable, such as `git config`.
42+
test "$(git config -f file-link a.b)" = "c" &&
43+
test "$(git config -f dir-link/file2 x.y)" = "z"
44+
'
45+
46+
test_done

0 commit comments

Comments
 (0)