Skip to content

Commit

Permalink
make git-clone GIT_WORK_TREE aware
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Matthias Lederhofer authored and Junio C Hamano committed Jul 6, 2007
1 parent 68ad891 commit 20ccef4
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions git-clone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 20ccef4

Please sign in to comment.