2007-03-26 23:15:32 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
usage () {
|
|
|
|
echo "usage:" $@
|
|
|
|
exit 127
|
|
|
|
}
|
|
|
|
|
|
|
|
die () {
|
|
|
|
echo $@
|
|
|
|
exit 128
|
|
|
|
}
|
|
|
|
|
|
|
|
if test $# -lt 2 || test $# -gt 3
|
|
|
|
then
|
|
|
|
usage "$0 <repository> <new_workdir> [<branch>]"
|
|
|
|
fi
|
|
|
|
|
|
|
|
orig_git=$1
|
|
|
|
new_workdir=$2
|
|
|
|
branch=$3
|
|
|
|
|
|
|
|
# want to make sure that what is pointed to has a .git directory ...
|
2007-05-27 03:09:27 +00:00
|
|
|
git_dir=$(cd "$orig_git" 2>/dev/null &&
|
|
|
|
git rev-parse --git-dir 2>/dev/null) ||
|
|
|
|
die "\"$orig_git\" is not a git repository!"
|
2007-03-26 23:15:32 +00:00
|
|
|
|
2007-08-22 01:50:12 +00:00
|
|
|
case "$git_dir" in
|
|
|
|
.git)
|
2007-06-19 11:44:43 +00:00
|
|
|
git_dir="$orig_git/.git"
|
2007-08-22 01:50:12 +00:00
|
|
|
;;
|
|
|
|
.)
|
|
|
|
git_dir=$orig_git
|
|
|
|
;;
|
|
|
|
esac
|
2007-06-19 11:44:43 +00:00
|
|
|
|
2007-08-22 05:33:49 +00:00
|
|
|
# don't link to a configured bare repository
|
|
|
|
isbare=$(git --git-dir="$git_dir" config --bool --get core.bare)
|
|
|
|
if test ztrue = z$isbare
|
|
|
|
then
|
|
|
|
die "\"$git_dir\" has core.bare set to true," \
|
|
|
|
" remove from \"$git_dir/config\" to use $0"
|
|
|
|
fi
|
|
|
|
|
2007-03-26 23:15:32 +00:00
|
|
|
# don't link to a workdir
|
2007-05-27 03:09:27 +00:00
|
|
|
if test -L "$git_dir/config"
|
2007-03-26 23:15:32 +00:00
|
|
|
then
|
|
|
|
die "\"$orig_git\" is a working directory only, please specify" \
|
|
|
|
"a complete repository."
|
|
|
|
fi
|
|
|
|
|
2007-09-06 03:33:41 +00:00
|
|
|
# don't recreate a workdir over an existing repository
|
|
|
|
if test -e "$new_workdir"
|
|
|
|
then
|
|
|
|
die "destination directory '$new_workdir' already exists."
|
|
|
|
fi
|
|
|
|
|
2007-03-26 23:15:32 +00:00
|
|
|
# make sure the the links use full paths
|
2007-05-27 03:09:27 +00:00
|
|
|
git_dir=$(cd "$git_dir"; pwd)
|
2007-03-26 23:15:32 +00:00
|
|
|
|
|
|
|
# create the workdir
|
|
|
|
mkdir -p "$new_workdir/.git" || die "unable to create \"$new_workdir\"!"
|
|
|
|
|
|
|
|
# create the links to the original repo. explictly exclude index, HEAD and
|
|
|
|
# logs/HEAD from the list since they are purely related to the current working
|
|
|
|
# directory, and should not be shared.
|
|
|
|
for x in config refs logs/refs objects info hooks packed-refs remotes rr-cache
|
|
|
|
do
|
|
|
|
case $x in
|
|
|
|
*/*)
|
|
|
|
mkdir -p "$(dirname "$new_workdir/.git/$x")"
|
|
|
|
;;
|
|
|
|
esac
|
2007-05-27 03:09:27 +00:00
|
|
|
ln -s "$git_dir/$x" "$new_workdir/.git/$x"
|
2007-03-26 23:15:32 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
# now setup the workdir
|
|
|
|
cd "$new_workdir"
|
|
|
|
# copy the HEAD from the original repository as a default branch
|
2007-05-27 03:09:27 +00:00
|
|
|
cp "$git_dir/HEAD" .git/HEAD
|
2007-03-26 23:15:32 +00:00
|
|
|
# checkout the branch (either the same as HEAD from the original repository, or
|
|
|
|
# the one that was asked for)
|
|
|
|
git checkout -f $branch
|