|
| 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 | +# MSYS2 is very forgiving, it will resolve symlinks even if the |
| 27 | +# symlink type isn't correct. To make this test meaningful, try |
| 28 | +# them with a native, non-MSYS executable. |
| 29 | +cat_native () { |
| 30 | + filename=$(cygpath -w "$1") && |
| 31 | + cmd.exe /c "type \"$filename\"" |
| 32 | +} |
| 33 | + |
| 34 | +test_expect_success 'checkout symlinks with attr' ' |
| 35 | + cache_symlink file1 file-link && |
| 36 | + cache_symlink dir dir-link && |
| 37 | +
|
| 38 | + printf "file-link symlink=file\ndir-link symlink=dir\n" >.gitattributes && |
| 39 | + git add .gitattributes && |
| 40 | +
|
| 41 | + git checkout . && |
| 42 | +
|
| 43 | + mkdir dir && |
| 44 | + echo "contents1" >file1 && |
| 45 | + echo "contents2" >dir/file2 && |
| 46 | +
|
| 47 | + test "$(cat_native file-link)" = "contents1" && |
| 48 | + test "$(cat_native dir-link/file2)" = "contents2" |
| 49 | +' |
| 50 | + |
| 51 | +test_done |
0 commit comments