summaryrefslogtreecommitdiff
path: root/git-clone.sh
diff options
context:
space:
mode:
authorMatthias Lederhofer <matled@gmx.net>2007-07-06 01:10:44 +0200
committerJunio C Hamano <gitster@pobox.com>2007-07-05 23:00:50 -0700
commit20ccef49689b3f4dc7510c63d9867e1969eed1e3 (patch)
tree4469e038ed2f8fe87b8af663dc79c88267525ddd /git-clone.sh
parent68ad8910f7b090a431b2da4e5f7be3de96112fa7 (diff)
downloadgit-20ccef49689b3f4dc7510c63d9867e1969eed1e3.tar.gz
make git-clone GIT_WORK_TREE aware
If GIT_WORK_TREE is set git-clone will use that path for the working tree. Signed-off-by: Matthias Lederhofer <matled@gmx.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-clone.sh')
-rwxr-xr-xgit-clone.sh25
1 files changed, 18 insertions, 7 deletions
diff --git a/git-clone.sh b/git-clone.sh
index 4ca91009dd..09225540e6 100755
--- a/git-clone.sh
+++ b/git-clone.sh
@@ -187,22 +187,29 @@ dir="$2"
# Try using "humanish" part of source repo if user didn't specify one
[ -z "$dir" ] && dir=$(echo "$repo" | sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
[ -e "$dir" ] && die "destination directory '$dir' already exists."
+[ yes = "$bare" ] && unset GIT_WORK_TREE
+[ -n "$GIT_WORK_TREE" ] && [ -e "$GIT_WORK_TREE" ] &&
+die "working tree '$GIT_WORK_TREE' already exists."
D=
+W=
cleanup() {
err=$?
test -z "$D" && rm -rf "$dir"
+ test -z "$W" && test -n "$GIT_WORK_TREE" && rm -rf "$GIT_WORK_TREE"
cd ..
test -n "$D" && rm -rf "$D"
+ test -n "$W" && rm -rf "$W"
exit $err
}
trap cleanup 0
mkdir -p "$dir" && D=$(cd "$dir" && pwd) || usage
-case "$bare" in
-yes)
- GIT_DIR="$D" ;;
-*)
- GIT_DIR="$D/.git" ;;
-esac &&
+test -n "$GIT_WORK_TREE" && mkdir -p "$GIT_WORK_TREE" &&
+W=$(cd "$GIT_WORK_TREE" && pwd) && export GIT_WORK_TREE="$W"
+if test yes = "$bare" || test -n "$GIT_WORK_TREE"; then
+ GIT_DIR="$D"
+else
+ GIT_DIR="$D/.git"
+fi &&
export GIT_DIR &&
git-init $quiet ${template+"$template"} || usage
@@ -358,7 +365,11 @@ then
done < "$GIT_DIR/CLONE_HEAD"
fi
-cd "$D" || exit
+if test -n "$W"; then
+ cd "$W" || exit
+else
+ cd "$D" || exit
+fi
if test -z "$bare" && test -f "$GIT_DIR/REMOTE_HEAD"
then