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

Commit 1919ecf

Browse files
committed
contrib: make git-new-workdir work with windows symlinks.
Required for tests to work. Signed-off-by: Michael Geddes <[email protected]>
1 parent 3259ff9 commit 1919ecf

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

contrib/workdir/git-new-workdir

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,52 @@
11
#!/bin/sh
22

3+
# Fix some commands on Windows
4+
case $(uname -s) in
5+
*MINGW*)
6+
winpath () {
7+
# pwd -W is the only way of getting msys to convert the path, especially mounted paths like /usr
8+
# since cmd /c only takes a single parameter preventing msys automatic path conversion.
9+
if test "${1:~-1:1}" != "/" ; then
10+
echo "$1" | sed 's+/+\\+g'
11+
elif test -d "$1" ; then
12+
(cd "$1"; pwd -W) | sed 's+/+\\+g'
13+
elif test -d "${1%/*}" ; then
14+
(cd "${1%/*}"; echo "$(pwd -W)/${1##*/}") | sed 's+/+\\+g'
15+
else
16+
echo "$1" | sed -e 's+^/\([a-z]\)/+\1:/+' -e 's+/+\\+g'
17+
fi
18+
}
19+
# git sees Windows-style pwd
20+
pwd () {
21+
builtin pwd -W
22+
}
23+
# use mklink
24+
ln () {
25+
26+
ln_sym_hard=/H
27+
ln_sym_dir=
28+
if test "$1" = "-s"
29+
then
30+
ln_sym_hard=
31+
shift
32+
fi
33+
pushd $(dirname "$2") 2>&1 > /dev/null
34+
builtin test -d "$1" && ln_sym_dir=/D
35+
popd > /dev/null 2> /dev/null
36+
cmd /c "mklink ${ln_sym_hard}${ln_sym_dir} \"$(winpath "$2")\" \"$(winpath "$1")\">/dev/null " 2>/dev/null
37+
}
38+
39+
test () {
40+
case "$1" in
41+
-h)
42+
test_file=$(cmd /c "@dir /b/a:l \"$(winpath "${2}")\" 2> nul" )
43+
builtin test -n "${test_file}"
44+
;;
45+
*) builtin test "$@";;
46+
esac
47+
}
48+
esac
49+
350
usage () {
451
echo "usage:" $@
552
exit 127
@@ -70,6 +117,7 @@ do
70117
mkdir -p "$(dirname "$new_workdir/.git/$x")"
71118
;;
72119
esac
120+
test -e "$git_dir/$x" || mkdir "$git_dir/$x"
73121
ln -s "$git_dir/$x" "$new_workdir/.git/$x"
74122
done
75123

0 commit comments

Comments
 (0)