13 if test $# -lt 2 || test $# -gt 3
15 usage "$0 <repository> <new_workdir> [<branch>]"
22 # want to make sure that what is pointed to has a .git directory ...
23 git_dir=$(cd "$orig_git" 2>/dev/null &&
24 git rev-parse --git-dir 2>/dev/null) ||
25 die "\"$orig_git\" is not a git repository!"
29 git_dir="$orig_git/.git"
36 # don't link to a configured bare repository
37 isbare=$(git --git-dir="$git_dir" config --bool --get core.bare)
38 if test ztrue = z$isbare
40 die "\"$git_dir\" has core.bare set to true," \
41 " remove from \"$git_dir/config\" to use $0"
44 # don't link to a workdir
45 if test -L "$git_dir/config"
47 die "\"$orig_git\" is a working directory only, please specify" \
48 "a complete repository."
51 # make sure the the links use full paths
52 git_dir=$(cd "$git_dir"; pwd)
55 mkdir -p "$new_workdir/.git" || die "unable to create \"$new_workdir\"!"
57 # create the links to the original repo. explictly exclude index, HEAD and
58 # logs/HEAD from the list since they are purely related to the current working
59 # directory, and should not be shared.
60 for x in config refs logs/refs objects info hooks packed-refs remotes rr-cache
64 mkdir -p "$(dirname "$new_workdir/.git/$x")"
67 ln -s "$git_dir/$x" "$new_workdir/.git/$x"
70 # now setup the workdir
72 # copy the HEAD from the original repository as a default branch
73 cp "$git_dir/HEAD" .git/HEAD
74 # checkout the branch (either the same as HEAD from the original repository, or
75 # the one that was asked for)
76 git checkout -f $branch