Browse Source

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>
maint
Matthias Lederhofer 18 years ago committed by Junio C Hamano
parent
commit
20ccef4968
  1. 25
      git-clone.sh

25
git-clone.sh

@ -187,22 +187,29 @@ dir="$2"
# Try using "humanish" part of source repo if user didn't specify one # 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') [ -z "$dir" ] && dir=$(echo "$repo" | sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
[ -e "$dir" ] && die "destination directory '$dir' already exists." [ -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= D=
W=
cleanup() { cleanup() {
err=$? err=$?
test -z "$D" && rm -rf "$dir" test -z "$D" && rm -rf "$dir"
test -z "$W" && test -n "$GIT_WORK_TREE" && rm -rf "$GIT_WORK_TREE"
cd .. cd ..
test -n "$D" && rm -rf "$D" test -n "$D" && rm -rf "$D"
test -n "$W" && rm -rf "$W"
exit $err exit $err
} }
trap cleanup 0 trap cleanup 0
mkdir -p "$dir" && D=$(cd "$dir" && pwd) || usage mkdir -p "$dir" && D=$(cd "$dir" && pwd) || usage
case "$bare" in test -n "$GIT_WORK_TREE" && mkdir -p "$GIT_WORK_TREE" &&
yes) W=$(cd "$GIT_WORK_TREE" && pwd) && export GIT_WORK_TREE="$W"
GIT_DIR="$D" ;; if test yes = "$bare" || test -n "$GIT_WORK_TREE"; then
*) GIT_DIR="$D"
GIT_DIR="$D/.git" ;; else
esac && GIT_DIR="$D/.git"
fi &&
export GIT_DIR && export GIT_DIR &&
git-init $quiet ${template+"$template"} || usage git-init $quiet ${template+"$template"} || usage


@ -358,7 +365,11 @@ then
done < "$GIT_DIR/CLONE_HEAD" done < "$GIT_DIR/CLONE_HEAD"
fi 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" if test -z "$bare" && test -f "$GIT_DIR/REMOTE_HEAD"
then then

Loading…
Cancel
Save