Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 4d733b9

Browse files
committed
test: Work around lack of windows native symlink support in current msys
The current msys does not have support for NTFS symlinks. This includes in 'ln', 'test', 'rm'. Here the commands are overridden to use windows cmd.exe instead of msys. The implementation of test is quite expensive but works for the test. 'rm' needs to handle many scenarios. Symlinks are not supported at all by the msys version. * 'rm -rf' equivalent needs to first delete the files, and then the directories. * Directory symbolic links need to use cmd.exe 'rmdir' * file symbolic links need to use 'del'. * A couple of places use 'rm -rf' on a mix of files and directories, so needs to be split up. Signed-off-by: Michael Geddes <[email protected]>
1 parent eabcbcc commit 4d733b9

File tree

3 files changed

+105
-2
lines changed

3 files changed

+105
-2
lines changed

t/t0050-filesystem.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ test_expect_success "detection of filesystem w/o symlink support during repo ini
4545
test "$(git config --bool core.symlinks)" = true
4646
'
4747
else
48-
test_expect_success "detection of filesystem w/o symlink support during repo init" '
48+
test_expect_failure "detection of filesystem w/o symlink support during repo init" '
4949
v=$(git config --bool core.symlinks) &&
5050
test "$v" = false
5151
'

t/t4004-diff-rename-symlink.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ test_expect_success SYMLINKS \
2222

2323
test_expect_success SYMLINKS \
2424
'prepare work tree' \
25-
'mv frotz rezrov &&
25+
'>xyzzy &&
26+
mv frotz rezrov &&
2627
rm -f yomin &&
28+
rm -f xyzzy &&
2729
ln -s xyzzy nitfol &&
2830
ln -s xzzzy bozbar &&
2931
git update-index --add --remove frotz rezrov nitfol bozbar yomin'

t/test-lib.sh

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,63 @@ case "$TRASH_DIRECTORY" in
694694
*) TRASH_DIRECTORY="$TEST_OUTPUT_DIRECTORY/$TRASH_DIRECTORY" ;;
695695
esac
696696
test ! -z "$debug" || remove_trash=$TRASH_DIRECTORY
697+
698+
case $(uname -s) in
699+
*MINGW*)
700+
# Converting to win32 path to supply to cmd.exe command.
701+
winpath () {
702+
# pwd -W is the only way of getting msys to convert the path, especially mounted paths like /usr
703+
# since cmd /c only takes a single parameter preventing msys automatic path conversion.
704+
if builtin test "${1:~-1:1}" != "/" ; then
705+
echo "$1" | sed 's+/+\\+g'
706+
elif builtin test -d "$1" ; then
707+
(cd "$1"; pwd -W) | sed 's+/+\\+g'
708+
elif builtin test -d "${1%/*}" ; then
709+
(cd "${1%/*}"; echo "$(pwd -W)/${1##*/}") | sed 's+/+\\+g'
710+
else
711+
echo "$1" | sed -e 's+^/\([a-z]\)/+\1:/+' -e 's+/+\\+g'
712+
fi
713+
}
714+
rm () {
715+
rm_is_f=0
716+
rm_is_r=0
717+
for ARG in "$@"
718+
do
719+
case "$ARG" in
720+
-rf|-fr) rm_is_r=1 ; rm_is_f=1 ;;
721+
-f) rm_is_f=1 ;;
722+
-r) rm_is_r=1 ;;
723+
-*) ;; # ignore
724+
*)
725+
rm_arg_winpath="$(winpath "$ARG")"
726+
if test -d "$ARG" ; then
727+
if test $rm_is_r -eq 1 ; then
728+
# Delete files, then remove directories.
729+
# Force so make sure the result is true
730+
cmd /c "del /s/q/f \"$rm_arg_winpath\" 2>nul && rmdir /q/s \"$rm_arg_winpath\" 2>nul" >/dev/null || true
731+
else
732+
# Works for symlinks as well
733+
cmd /c "@rmdir /q \"$rm_arg_winpath\""
734+
fi
735+
builtin test -d "$ARG" && echo "rm: unable to delete \"$ARG\"" 1>&2 && return 1
736+
else
737+
# Using del works for symlinks as well
738+
if test $rm_is_f -eq 1 ; then
739+
# Force so make sure the result is true
740+
cmd /c "@del /q/f \"$rm_arg_winpath\" 2>nul" >/dev/null || true
741+
else
742+
cmd /c "@del /q/f \"$rm_arg_winpath\" 2>nul" >/dev/null
743+
fi
744+
test -f "$ARG" && echo "rm: unable to delete \"$ARG\"" 1>&2 && return 1
745+
fi
746+
;;
747+
esac
748+
done
749+
return 0
750+
}
751+
;;
752+
esac
753+
697754
rm -fr "$TRASH_DIRECTORY" || {
698755
GIT_EXIT_OK=t
699756
echo >&5 "FATAL: Cannot prepare test area"
@@ -754,6 +811,49 @@ case $(uname -s) in
754811
pwd () {
755812
builtin pwd -W
756813
}
814+
# use mklink
815+
ln () {
816+
817+
ln_sym_hard=/H
818+
ln_sym_dir=
819+
if test "$1" = "-s"
820+
then
821+
ln_sym_hard=
822+
shift
823+
fi
824+
pushd $(dirname "$2") 2>&1 > /dev/null
825+
builtin test -d "$1" && ln_sym_dir=/D
826+
popd > /dev/null 2> /dev/null
827+
cmd /c "mklink ${ln_sym_hard}${ln_sym_dir} \"$(winpath "$2")\" \"$(winpath "$1")\">/dev/null " 2>/dev/null
828+
ln_eval_ret=$?
829+
if test $ln_eval_ret != 0 -a -n "$ln_sym_hard" ; then
830+
cp "$1" "$2"
831+
else
832+
return $ln_eval_ret
833+
fi
834+
}
835+
test () {
836+
case "$1" in
837+
-[hL])
838+
if builtin test -d "$2" ; then
839+
test_sym_dir=$(dirname "$2")
840+
builtin test -n "${test_sym_dir}" && pushd "${test_sym_dir}" 2>&1 > /dev/null
841+
test_sym_base=$(basename "$2")
842+
test_file=$(cmd /c "@dir /b/a:l \"${test_sym_base}?\" 2> nul" | grep "^${test_sym_base}$" )
843+
builtin test -n "${test_sym_dir}" && popd 2>&1 > /dev/null
844+
builtin test -n "${test_file}"
845+
else
846+
test_file=$(cmd /c "@dir /b/a:l \"$(winpath "$2")\" 2> nul" )
847+
builtin test -n "${test_file}"
848+
fi
849+
;;
850+
-f)
851+
test_file=$(cmd /c "@dir /b/a:-d-l-s \"$(winpath "$2")\" 2> nul" )
852+
builtin test -n "${test_file}"
853+
;;
854+
*) builtin test "$@";;
855+
esac
856+
}
757857
# no POSIX permissions
758858
# backslashes in pathspec are converted to '/'
759859
# exec does not inherit the PID
@@ -837,6 +937,7 @@ test_lazy_prereq PIPE '
837937

838938
test_lazy_prereq SYMLINKS '
839939
# test whether the filesystem supports symbolic links
940+
touch x
840941
ln -s x y && test -h y
841942
'
842943

0 commit comments

Comments
 (0)