[PATCH 1/2] git-clone: split up long &&-command-chain and use a function for cleanup

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Matthias Lederhofer <matled@xxxxxxx>
---
This is in preparation for the next patch.

Actually the old cleanup code could leave the repository directory if
    D=$(cd "$dir" && pwd)
failed before this patch.
---
 git-clone.sh |   17 +++++++++++++----
 1 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/git-clone.sh b/git-clone.sh
index bd44ce1..59a457b 100755
--- a/git-clone.sh
+++ b/git-clone.sh
@@ -176,15 +176,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 ${template+"$template"} || usage
+esac
+export GIT_DIR
+git-init ${template+"$template"} || usage
 
 if test -n "$reference"
 then
-- 
1.5.2.2.647.ga00fe

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux