{"thread":{"id":"5973","subject":"[PATCH] git-clone: define die() and use it.","startedAt":"2006-10-20T19:38:31Z","lastAt":"2006-10-20T19:38:31Z","messageCount":1,"participants":["Dmitry V. Levin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"29412","messageId":"20061020193831.GA24237@nomad.office.altlinux.org","threadId":"5973","inReplyTo":null,"subject":"[PATCH] git-clone: define die() and use it.","fromName":"Dmitry V. Levin","fromEmail":"ldv@altlinux.org","sentAt":"2006-10-20T19:38:31Z","receivedAt":"2006-10-20T19:38:31Z","isPatch":true,"sender":{"key":"ldv@altlinux.org","avatar":"https://avatars.githubusercontent.com/u/5281408?v=4"},"body":"Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>\n---\n git-clone.sh |   61 +++++++++++++++++++++++-----------------------------------\n 1 files changed, 24 insertions(+), 37 deletions(-)\n\ndiff --git a/git-clone.sh b/git-clone.sh\nindex bf54a11..786d65a 100755\n--- a/git-clone.sh\n+++ b/git-clone.sh\n@@ -8,11 +8,15 @@ # Clone a repository into a different di\n # See git-sh-setup why.\n unset CDPATH\n \n-usage() {\n-\techo >&2 \"Usage: $0 [--template=<template_directory>] [--use-separate-remote] [--reference <reference-repo>] [--bare] [-l [-s]] [-q] [-u <upload-pack>] [--origin <name>] [-n] <repo> [<dir>]\"\n+die() {\n+\techo >&2 \"$@\"\n \texit 1\n }\n \n+usage() {\n+\tdie \"Usage: $0 [--template=<template_directory>] [--use-separate-remote] [--reference <reference-repo>] [--bare] [-l [-s]] [-q] [-u <upload-pack>] [--origin <name>] [-n] <repo> [<dir>]\"\n+}\n+\n get_repo_base() {\n \t(cd \"$1\" && (cd .git ; pwd)) 2> /dev/null\n }\n@@ -35,11 +39,9 @@ clone_dumb_http () {\n \t\t\"`git-repo-config --bool http.noEPSV`\" = true ]; then\n \t\tcurl_extra_args=\"${curl_extra_args} --disable-epsv\"\n \tfi\n-\thttp_fetch \"$1/info/refs\" \"$clone_tmp/refs\" || {\n-\t\techo >&2 \"Cannot get remote repository information.\n+\thttp_fetch \"$1/info/refs\" \"$clone_tmp/refs\" ||\n+\t\tdie \"Cannot get remote repository information.\n Perhaps git-update-server-info needs to be run there?\"\n-\t\texit 1;\n-\t}\n \twhile read sha1 refname\n \tdo\n \t\tname=`expr \"z$refname\" : 'zrefs/\\(.*\\)'` &&\n@@ -143,17 +145,12 @@ while\n \t\t'')\n \t\t    usage ;;\n \t\t*/*)\n-\t\t    echo >&2 \"'$2' is not suitable for an origin name\"\n-\t\t    exit 1\n+\t\t    die \"'$2' is not suitable for an origin name\"\n \t\tesac\n-\t\tgit-check-ref-format \"heads/$2\" || {\n-\t\t    echo >&2 \"'$2' is not suitable for a branch name\"\n-\t\t    exit 1\n-\t\t}\n-\t\ttest -z \"$origin_override\" || {\n-\t\t    echo >&2 \"Do not give more than one --origin options.\"\n-\t\t    exit 1\n-\t\t}\n+\t\tgit-check-ref-format \"heads/$2\" ||\n+\t\t    die \"'$2' is not suitable for a branch name\"\n+\t\ttest -z \"$origin_override\" ||\n+\t\t    die \"Do not give more than one --origin options.\"\n \t\torigin_override=yes\n \t\torigin=\"$2\"; shift\n \t\t;;\n@@ -169,24 +166,19 @@ do\n done\n \n repo=\"$1\"\n-if test -z \"$repo\"\n-then\n-    echo >&2 'you must specify a repository to clone.'\n-    exit 1\n-fi\n+test -n \"$repo\" ||\n+    die 'you must specify a repository to clone.'\n \n # --bare implies --no-checkout\n if test yes = \"$bare\"\n then\n \tif test yes = \"$origin_override\"\n \tthen\n-\t\techo >&2 '--bare and --origin $origin options are incompatible.'\n-\t\texit 1\n+\t\tdie '--bare and --origin $origin options are incompatible.'\n \tfi\n \tif test t = \"$use_separate_remote\"\n \tthen\n-\t\techo >&2 '--bare and --use-separate-remote options are incompatible.'\n-\t\texit 1\n+\t\tdie '--bare and --use-separate-remote options are incompatible.'\n \tfi\n \tno_checkout=yes\n fi\n@@ -206,7 +198,7 @@ fi\n 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\" ] && echo \"$dir already exists.\" && usage\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@@ -233,7 +225,7 @@ then\n \t\t cd reference-tmp &&\n \t\t tar xf -)\n \telse\n-\t\techo >&2 \"$reference: not a local directory.\" && usage\n+\t\tdie \"reference repository '$reference' is not a local directory.\"\n \tfi\n fi\n \n@@ -242,10 +234,8 @@ rm -f \"$GIT_DIR/CLONE_HEAD\"\n # We do local magic only when the user tells us to.\n case \"$local,$use_local\" in\n yes,yes)\n-\t( cd \"$repo/objects\" ) || {\n-\t\techo >&2 \"-l flag seen but $repo is not local.\"\n-\t\texit 1\n-\t}\n+\t( cd \"$repo/objects\" ) ||\n+\t\tdie \"-l flag seen but repository '$repo' is not local.\"\n \n \tcase \"$local_shared\" in\n \tno)\n@@ -307,18 +297,15 @@ yes,yes)\n \t\tthen\n \t\t\tclone_dumb_http \"$repo\" \"$D\"\n \t\telse\n-\t\t\techo >&2 \"http transport not supported, rebuild Git with curl support\"\n-\t\t\texit 1\n+\t\t\tdie \"http transport not supported, rebuild Git with curl support\"\n \t\tfi\n \t\t;;\n \t*)\n \t\tcase \"$upload_pack\" in\n \t\t'') git-fetch-pack --all -k $quiet \"$repo\" ;;\n \t\t*) git-fetch-pack --all -k $quiet \"$upload_pack\" \"$repo\" ;;\n-\t\tesac >\"$GIT_DIR/CLONE_HEAD\" || {\n-\t\t\techo >&2 \"fetch-pack from '$repo' failed.\"\n-\t\t\texit 1\n-\t\t}\n+\t\tesac >\"$GIT_DIR/CLONE_HEAD\" ||\n+\t\t\tdie \"fetch-pack from '$repo' failed.\"\n \t\t;;\n \tesac\n \t;;\n-- \n1.4.3.GIT\n"}]}