2007-03-27 03:15:32 +04: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 07:09:27 +04:00
|
|
|
git_dir=$(cd "$orig_git" 2>/dev/null &&
|
|
|
|
git rev-parse --git-dir 2>/dev/null) ||
|
2008-12-22 02:17:32 +03:00
|
|
|
die "Not a git repository: \"$orig_git\""
|
2007-03-27 03:15:32 +04:00
|
|
|
|
2007-08-22 05:50:12 +04:00
|
|
|
case "$git_dir" in
|
|
|
|
.git)
|
2007-06-19 15:44:43 +04:00
|
|
|
git_dir="$orig_git/.git"
|
2007-08-22 05:50:12 +04:00
|
|
|
;;
|
|
|
|
.)
|
|
|
|
git_dir=$orig_git
|
|
|
|
;;
|
|
|
|
esac
|
2007-06-19 15:44:43 +04:00
|
|
|
|
2007-08-22 09:33:49 +04: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-27 03:15:32 +04:00
|
|
|
# don't link to a workdir
|
2007-05-27 07:09:27 +04:00
|
|
|
if test -L "$git_dir/config"
|
2007-03-27 03:15:32 +04:00
|
|
|
then
|
|
|
|
die "\"$orig_git\" is a working directory only, please specify" \
|
|
|
|
"a complete repository."
|
|
|
|
fi
|
|
|
|
|
2007-09-06 07:33:41 +04: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-27 03:15:32 +04:00
|
|
|
# make sure the the links use full paths
|
2007-05-27 07:09:27 +04:00
|
|
|
git_dir=$(cd "$git_dir"; pwd)
|
2007-03-27 03:15:32 +04: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.
|
2008-03-15 05:44:13 +03:00
|
|
|
for x in config refs logs/refs objects info hooks packed-refs remotes rr-cache svn
|
2007-03-27 03:15:32 +04:00
|
|
|
do
|
|
|
|
case $x in
|
|
|
|
*/*)
|
|
|
|
mkdir -p "$(dirname "$new_workdir/.git/$x")"
|
|
|
|
;;
|
|
|
|
esac
|
2007-05-27 07:09:27 +04:00
|
|
|
ln -s "$git_dir/$x" "$new_workdir/.git/$x"
|
2007-03-27 03:15:32 +04:00
|
|
|
done
|
|
|
|
|
|
|
|
# now setup the workdir
|
|
|
|
cd "$new_workdir"
|
|
|
|
# copy the HEAD from the original repository as a default branch
|
2007-05-27 07:09:27 +04:00
|
|
|
cp "$git_dir/HEAD" .git/HEAD
|
2007-03-27 03:15:32 +04:00
|
|
|
# checkout the branch (either the same as HEAD from the original repository, or
|
|
|
|
# the one that was asked for)
|
|
|
|
git checkout -f $branch
|