3 # Fix some commands on Windows
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'
16 echo "$1" |
sed -e 's+^/\([a-z]\)/+\1:/+' -e 's+/+\\+g'
19 # git sees Windows-style pwd
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
42 test_file
=$
(cmd
/c
"@dir /b/a:l \"$(winpath "${2}")\" 2> nul" )
43 builtin test -n "${test_file}"
45 *) builtin test "$@";;
60 if test $# -lt 2 ||
test $# -gt 3
62 usage
"$0 <repository> <new_workdir> [<branch>]"
69 # want to make sure that what is pointed to has a .git directory ...
70 git_dir
=$
(cd "$orig_git" 2>/dev
/null
&&
71 git rev-parse
--git-dir 2>/dev
/null
) ||
72 die
"Not a git repository: \"$orig_git\""
76 git_dir
="$orig_git/.git"
83 # don't link to a configured bare repository
84 isbare
=$
(git
--git-dir="$git_dir" config
--bool --get core.bare
)
85 if test ztrue
= z
$isbare
87 die
"\"$git_dir\" has core.bare set to true," \
88 " remove from \"$git_dir/config\" to use $0"
91 # don't link to a workdir
92 if test -h "$git_dir/config"
94 die
"\"$orig_git\" is a working directory only, please specify" \
95 "a complete repository."
98 # don't recreate a workdir over an existing repository
99 if test -e "$new_workdir"
101 die
"destination directory '$new_workdir' already exists."
104 # make sure the links use full paths
105 git_dir
=$
(cd "$git_dir"; pwd)
108 mkdir
-p "$new_workdir/.git" || die
"unable to create \"$new_workdir\"!"
110 # create the links to the original repo. explicitly exclude index, HEAD and
111 # logs/HEAD from the list since they are purely related to the current working
112 # directory, and should not be shared.
113 for x
in config refs logs
/refs objects info hooks packed-refs remotes rr-cache svn
117 mkdir
-p "$(dirname "$new_workdir/.git
/$x")"
120 test -e "$git_dir/$x" || mkdir
"$git_dir/$x"
121 ln -s "$git_dir/$x" "$new_workdir/.git/$x"
124 # now setup the workdir
126 # copy the HEAD from the original repository as a default branch
127 cp "$git_dir/HEAD" .git
/HEAD
128 # checkout the branch (either the same as HEAD from the original repository, or
129 # the one that was asked for)
130 git checkout
-f $branch