{"thread":{"id":"8885","subject":"[PATCH 1/2] git-clone: split up long &&-command-chain and use a function for cleanup","startedAt":"2007-07-05T22:54:33Z","lastAt":"2007-07-05T23:10:44Z","messageCount":2,"participants":["Matthias Lederhofer"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"46574","messageId":"20070705225433.GA26061@moooo.ath.cx","threadId":"8885","inReplyTo":null,"subject":"[PATCH 1/2] git-clone: split up long &&-command-chain and use a function for cleanup","fromName":"Matthias Lederhofer","fromEmail":"matled@gmx.net","sentAt":"2007-07-05T22:54:33Z","receivedAt":"2007-07-05T22:54:33Z","isPatch":true,"sender":{"key":"matled@gmx.net","avatar":null},"body":"Signed-off-by: Matthias Lederhofer <matled@gmx.net>\n---\nThis is in preparation for the next patch.\n\nActually the old cleanup code could leave the repository directory if\n    D=$(cd \"$dir\" && pwd)\nfailed before this patch.\n---\n git-clone.sh |   17 +++++++++++++----\n 1 files changed, 13 insertions(+), 4 deletions(-)\n\ndiff --git a/git-clone.sh b/git-clone.sh\nindex bd44ce1..59a457b 100755\n--- a/git-clone.sh\n+++ b/git-clone.sh\n@@ -176,15 +176,24 @@ dir=\"$2\"\n # Try using \"humanish\" part of source repo if user didn't specify one\n [ -z \"$dir\" ] && dir=$(echo \"$repo\" | sed -e 's|/$||' -e 's|:*/*\\.git$||' -e 's|.*[/:]||g')\n [ -e \"$dir\" ] && die \"destination directory '$dir' already exists.\"\n-mkdir -p \"$dir\" &&\n-D=$(cd \"$dir\" && pwd) &&\n-trap 'err=$?; cd ..; rm -rf \"$D\"; exit $err' 0\n+D=\n+cleanup() {\n+\terr=$?\n+\ttest -z \"$D\" && rm -rf \"$dir\"\n+\tcd ..\n+\ttest -n \"$D\" && rm -rf \"$D\"\n+\texit $err\n+}\n+trap cleanup 0\n+mkdir -p \"$dir\" && D=$(cd \"$dir\" && pwd) || usage\n case \"$bare\" in\n yes)\n \tGIT_DIR=\"$D\" ;;\n *)\n \tGIT_DIR=\"$D/.git\" ;;\n-esac && export GIT_DIR && git-init ${template+\"$template\"} || usage\n+esac\n+export GIT_DIR\n+git-init ${template+\"$template\"} || usage\n \n if test -n \"$reference\"\n then\n-- \n1.5.2.2.647.ga00fe\n"},{"id":"46575","messageId":"20070705231044.GB26061@moooo.ath.cx","threadId":"8885","inReplyTo":"20070705225433.GA26061@moooo.ath.cx","subject":"[PATCH 2/2] make git-clone GIT_WORK_TREE aware","fromName":"Matthias Lederhofer","fromEmail":"matled@gmx.net","sentAt":"2007-07-05T23:10:44Z","receivedAt":"2007-07-05T23:10:44Z","isPatch":true,"sender":{"key":"matled@gmx.net","avatar":null},"body":"If GIT_WORK_TREE is set git-clone will use that path for the\nworking tree.\n\nSigned-off-by: Matthias Lederhofer <matled@gmx.net>\n---\nAll those import scripts which call git init too probably have\nproblems when GIT_WORK_TREE is exported.  Perhaps a simple\n\n    test -n \"$GIT_WORK_TREE\" ||\n    die \"GIT_WORK_TREE is not supported by this script yet\"\n\nis enough for the moment for those scripts.\n---\n git-clone.sh |   25 ++++++++++++++++++-------\n 1 files changed, 18 insertions(+), 7 deletions(-)\n\ndiff --git a/git-clone.sh b/git-clone.sh\nindex 59a457b..b72a242 100755\n--- a/git-clone.sh\n+++ b/git-clone.sh\n@@ -176,22 +176,29 @@ dir=\"$2\"\n # Try using \"humanish\" part of source repo if user didn't specify one\n [ -z \"$dir\" ] && dir=$(echo \"$repo\" | sed -e 's|/$||' -e 's|:*/*\\.git$||' -e 's|.*[/:]||g')\n [ -e \"$dir\" ] && die \"destination directory '$dir' already exists.\"\n+[ yes = \"$bare\" ] && unset GIT_WORK_TREE\n+[ -n \"$GIT_WORK_TREE\" ] && [ -e \"$GIT_WORK_TREE\" ] &&\n+die \"working tree '$GIT_WORK_TREE' already exists.\"\n D=\n+W=\n cleanup() {\n \terr=$?\n \ttest -z \"$D\" && rm -rf \"$dir\"\n+\ttest -z \"$W\" && test -n \"$GIT_WORK_TREE\" && rm -rf \"$GIT_WORK_TREE\"\n \tcd ..\n \ttest -n \"$D\" && rm -rf \"$D\"\n+\ttest -n \"$W\" && rm -rf \"$W\"\n \texit $err\n }\n trap cleanup 0\n mkdir -p \"$dir\" && D=$(cd \"$dir\" && pwd) || usage\n-case \"$bare\" in\n-yes)\n-\tGIT_DIR=\"$D\" ;;\n-*)\n-\tGIT_DIR=\"$D/.git\" ;;\n-esac\n+test -n \"$GIT_WORK_TREE\" && mkdir -p \"$GIT_WORK_TREE\" &&\n+W=$(cd \"$GIT_WORK_TREE\" && pwd) && export GIT_WORK_TREE=\"$W\"\n+if test yes = \"$bare\" || test -n \"$GIT_WORK_TREE\"; then\n+\tGIT_DIR=\"$D\"\n+else\n+\tGIT_DIR=\"$D/.git\"\n+fi\n export GIT_DIR\n git-init ${template+\"$template\"} || usage\n \n@@ -347,7 +354,11 @@ then\n \tdone < \"$GIT_DIR/CLONE_HEAD\"\n fi\n \n-cd \"$D\" || exit\n+if test -n \"$W\"; then\n+\tcd \"$W\" || exit\n+else\n+\tcd \"$D\" || exit\n+fi\n \n if test -z \"$bare\" && test -f \"$GIT_DIR/REMOTE_HEAD\"\n then\n-- \n1.5.2.2.647.ga00fe\n"}]}