2007-03-27 01:15:32 +02: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 05:09:27 +02:00
|
|
|
git_dir=$(cd "$orig_git" 2>/dev/null &&
|
|
|
|
git rev-parse --git-dir 2>/dev/null) ||
|
2008-12-22 00:17:32 +01:00
|
|
|
die "Not a git repository: \"$orig_git\""
|
2007-03-27 01:15:32 +02:00
|
|
|
|
2007-08-22 03:50:12 +02:00
|
|
|
case "$git_dir" in
|
|
|
|
.git)
|
2007-06-19 13:44:43 +02:00
|
|
|
git_dir="$orig_git/.git"
|
2007-08-22 03:50:12 +02:00
|
|
|
;;
|
|
|
|
.)
|
|
|
|
git_dir=$orig_git
|
|
|
|
;;
|
|
|
|
esac
|
2007-06-19 13:44:43 +02:00
|
|
|
|
2007-08-22 07:33:49 +02: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 01:15:32 +02:00
|
|
|
# don't link to a workdir
|
2010-09-22 02:35:59 +02:00
|
|
|
if test -h "$git_dir/config"
|
2007-03-27 01:15:32 +02:00
|
|
|
then
|
|
|
|
die "\"$orig_git\" is a working directory only, please specify" \
|
|
|
|
"a complete repository."
|
|
|
|
fi
|
|
|
|
|
2007-09-06 05:33:41 +02:00
|
|
|
# don't recreate a workdir over an existing repository
|
|
|
|
if test -e "$new_workdir"
|
|
|
|
then
|
|
|
|
die "destination directory '$new_workdir' already exists."
|
|
|
|
fi
|
|
|
|
|
2010-08-22 13:12:12 +02:00
|
|
|
# make sure the links use full paths
|
2007-05-27 05:09:27 +02:00
|
|
|
git_dir=$(cd "$git_dir"; pwd)
|
2007-03-27 01:15:32 +02:00
|
|
|
|
|
|
|
# create the workdir
|
|
|
|
mkdir -p "$new_workdir/.git" || die "unable to create \"$new_workdir\"!"
|
|
|
|
|
2010-08-22 13:12:12 +02:00
|
|
|
# create the links to the original repo. explicitly exclude index, HEAD and
|
2007-03-27 01:15:32 +02:00
|
|
|
# logs/HEAD from the list since they are purely related to the current working
|
|
|
|
# directory, and should not be shared.
|
2008-03-15 03:44:13 +01:00
|
|
|
for x in config refs logs/refs objects info hooks packed-refs remotes rr-cache svn
|
2007-03-27 01:15:32 +02:00
|
|
|
do
|
|
|
|
case $x in
|
|
|
|
*/*)
|
|
|
|
mkdir -p "$(dirname "$new_workdir/.git/$x")"
|
|
|
|
;;
|
|
|
|
esac
|
2007-05-27 05:09:27 +02:00
|
|
|
ln -s "$git_dir/$x" "$new_workdir/.git/$x"
|
2007-03-27 01:15:32 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
# now setup the workdir
|
|
|
|
cd "$new_workdir"
|
|
|
|
# copy the HEAD from the original repository as a default branch
|
2007-05-27 05:09:27 +02:00
|
|
|
cp "$git_dir/HEAD" .git/HEAD
|
2007-03-27 01:15:32 +02:00
|
|
|
# checkout the branch (either the same as HEAD from the original repository, or
|
|
|
|
# the one that was asked for)
|
|
|
|
git checkout -f $branch
|