From: Matthias Lederhofer Date: Thu, 5 Jul 2007 22:54:33 +0000 (+0200) Subject: git-clone: split up long &&-command-chain and use a function for cleanup X-Git-Tag: v1.5.3-rc1~69 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=68ad8910f7b090a431b2da4e5f7be3de96112fa7;p=git.git git-clone: split up long &&-command-chain and use a function for cleanup Signed-off-by: Matthias Lederhofer Signed-off-by: Junio C Hamano --- diff --git a/git-clone.sh b/git-clone.sh index 48dafa21c..4ca91009d 100755 --- a/git-clone.sh +++ b/git-clone.sh @@ -187,15 +187,24 @@ 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." -mkdir -p "$dir" && -D=$(cd "$dir" && pwd) && -trap 'err=$?; cd ..; rm -rf "$D"; exit $err' 0 +D= +cleanup() { + err=$? + test -z "$D" && rm -rf "$dir" + cd .. + test -n "$D" && rm -rf "$D" + 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 && export GIT_DIR && git init $quiet ${template+"$template"} || usage +esac && +export GIT_DIR && +git-init $quiet ${template+"$template"} || usage if test -n "$reference" then