git-clone: split up long &&-command-chain and use a function for cleanup
Signed-off-by: Matthias Lederhofer <matled@gmx.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Matthias Lederhofer committed
Jul 6, 2007 at 00:54 UTC
68ad8910f7b090a431b2da4e5f7be3de96112fa7
1 file changed
+13
-4
git-clone.sh
+13
-4
@@ -187,15 +187,24 @@ 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
-mkdir -p "$dir" &&
191
-D=$(cd "$dir" && pwd) &&
192
-trap 'err=$?; cd ..; rm -rf "$D"; exit $err' 0
190
+D=
191
+cleanup() {
192
+ err=$?
193
+ test -z "$D" && rm -rf "$dir"
194
+ cd ..
195
+ test -n "$D" && rm -rf "$D"
196
+ exit $err
197
+}
198
+trap cleanup 0
199
+mkdir -p "$dir" && D=$(cd "$dir" && pwd) || usage
200
case "$bare" in
201
yes)
202
GIT_DIR="$D" ;;
203
*)
204
GIT_DIR="$D/.git" ;;
198
-esac && export GIT_DIR && git init $quiet ${template+"$template"} || usage
205
+esac &&
206
+export GIT_DIR &&
207
+git-init $quiet ${template+"$template"} || usage
208
209
if test -n "$reference"
210
then