@matheusbsbs / matheus-bagliano / commits / 20ccef4968
Fork 0

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>

Matthias Lederhofer committed Jul 6, 2007 at 01:10 UTC 20ccef49689b3f4dc7510c63d9867e1969eed1e3
1 file changed +18 -7
git-clone.sh
+18 -7
@@ -187,22 +187,29 @@ dir="$2"
187 # Try using "humanish" part of source repo if user didn't specify one
188 [ -z "$dir" ] && dir=$(echo "$repo" | sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
189 [ -e "$dir" ] && die "destination directory '$dir' already exists."
190 +[ yes = "$bare" ] && unset GIT_WORK_TREE
191 +[ -n "$GIT_WORK_TREE" ] && [ -e "$GIT_WORK_TREE" ] &&
192 +die "working tree '$GIT_WORK_TREE' already exists."
193 D=
194 +W=
195 cleanup() {
196 err=$?
197 test -z "$D" && rm -rf "$dir"
198 + test -z "$W" && test -n "$GIT_WORK_TREE" && rm -rf "$GIT_WORK_TREE"
199 cd ..
200 test -n "$D" && rm -rf "$D"
201 + test -n "$W" && rm -rf "$W"
202 exit $err
203 }
204 trap cleanup 0
205 mkdir -p "$dir" && D=$(cd "$dir" && pwd) || usage
200 -case "$bare" in
201 -yes)
202 - GIT_DIR="$D" ;;
203 -*)
204 - GIT_DIR="$D/.git" ;;
205 -esac &&
206 +test -n "$GIT_WORK_TREE" && mkdir -p "$GIT_WORK_TREE" &&
207 +W=$(cd "$GIT_WORK_TREE" && pwd) && export GIT_WORK_TREE="$W"
208 +if test yes = "$bare" || test -n "$GIT_WORK_TREE"; then
209 + GIT_DIR="$D"
210 +else
211 + GIT_DIR="$D/.git"
212 +fi &&
213 export GIT_DIR &&
214 git-init $quiet ${template+"$template"} || usage
215
@@ -358,7 +365,11 @@ then
365 done < "$GIT_DIR/CLONE_HEAD"
366 fi
367
361 -cd "$D" || exit
368 +if test -n "$W"; then
369 + cd "$W" || exit
370 +else
371 + cd "$D" || exit
372 +fi
373
374 if test -z "$bare" && test -f "$GIT_DIR/REMOTE_HEAD"
375 then