git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthias Lederhofer <matled@gmx.net>
To: git@vger.kernel.org
Subject: [PATCH 1/2] git-clone: split up long &&-command-chain and use a function for cleanup
Date: Fri, 6 Jul 2007 00:54:33 +0200	[thread overview]
Message-ID: <20070705225433.GA26061@moooo.ath.cx> (raw)

Signed-off-by: Matthias Lederhofer <matled@gmx.net>
---
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

             reply	other threads:[~2007-07-05 22:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-05 22:54 Matthias Lederhofer [this message]
2007-07-05 23:10 ` [PATCH 2/2] make git-clone GIT_WORK_TREE aware Matthias Lederhofer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070705225433.GA26061@moooo.ath.cx \
    --to=matled@gmx.net \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).