13 if test $# -lt 2 ||
test $# -gt 2
15 usage
"$0 <repository> <new_workdir>"
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
"Not a git repository: \"$orig_git\""
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 -h "$git_dir/config"
47 die
"\"$orig_git\" is a working directory only, please specify" \
48 "a complete repository."
53 die
"the current directory is not a git workdir"
56 # don't recreate a workdir over an existing repository
57 if test -e "$new_workdir/.git"
59 die
"destination directory '$new_workdir' already exists."
62 # make sure the links use full paths
63 git_dir
=$
(cd "$git_dir"; pwd)
66 mkdir
-p ".git/modules/$new_workdir" || die
"unable to create \".git/modules/$new_workdir\"!"
68 # create the links to the original repo. explicitly exclude index, HEAD and
69 # logs/HEAD from the list since they are purely related to the current working
70 # directory, and should not be shared.
71 ## LEM: add branches; deprecated, but safer to include it
72 for x
in branches config refs logs
/refs objects info hooks packed-refs remotes rr-cache svn
76 mkdir
-p "$(dirname ".git
/modules
/$new_workdir/$x")"
79 ln -s "$git_dir/$x" ".git/modules/$new_workdir/$x"
82 # now setup the workdir
83 mkdir
-p "$new_workdir"
85 echo "gitdir: ../.git/modules/$new_workdir" > .git
86 # copy the HEAD from the original repository as a default branch
87 cp "$git_dir/HEAD" ..
/.git
/modules
/$new_workdir/HEAD
88 # don't checkout the branch, a subsequent "git module update" will do it