{"thread":{"id":"10595","subject":"[PATCH] Migrate git-clone to use git-parseopt(1)","startedAt":"2007-11-02T15:09:21Z","lastAt":"2007-11-02T15:58:03Z","messageCount":2,"participants":["Pierre Habouzit"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"298998","messageId":"1194016162-23599-4-git-send-email-madcoder@debian.org","threadId":"10595","inReplyTo":"1194016162-23599-3-git-send-email-madcoder@debian.org","subject":"[PATCH] Migrate git-clean.sh to use git-parseoptions(1)","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2007-11-02T15:09:21Z","receivedAt":"2007-11-02T15:09:21Z","isPatch":true,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"Also minor consistency tweaks in how errors are caught.\n---\n\n    This patch is a pretty good example of the fact that git-parseopt(1)\n    is not very disruptive to the general coding style thanks to\n    git-sh-setup.\n\n git-clean.sh |   38 ++++++++++++++++++++------------------\n 1 files changed, 20 insertions(+), 18 deletions(-)\n\ndiff --git a/git-clean.sh b/git-clean.sh\nindex 4491738..6959433 100755\n--- a/git-clean.sh\n+++ b/git-clean.sh\n@@ -3,16 +3,21 @@\n # Copyright (c) 2005-2006 Pavel Roskin\n #\n \n-USAGE=\"[-d] [-f] [-n] [-q] [-x | -X] [--] <paths>...\"\n-LONG_USAGE='Clean untracked files from the working directory\n-\t-d\tremove directories as well\n-\t-f\toverride clean.requireForce and clean anyway\n-\t-n \tdon'\\''t remove anything, just show what would be done\n-\t-q\tbe quiet, only report errors\n-\t-x\tremove ignored files as well\n-\t-X\tremove only ignored files\n+OPTIONS_SPEC=\"\\\n+git-clean [options] <paths>...\n+\n+Clean untracked files from the working directory\n+\n When optional <paths>... arguments are given, the paths\n-affected are further limited to those that match them.'\n+affected are further limited to those that match them.\n+--\n+d remove directories as well\n+f override clean.requireForce and clean anyway\n+n don't remove anything, just show what would be done\n+q be quiet, only report errors\n+x remove ignored files as well\n+X remove only ignored files\"\n+\n SUBDIRECTORY_OK=Yes\n . git-sh-setup\n require_work_tree\n@@ -55,23 +60,20 @@ do\n \t\tshift\n \t\tbreak\n \t\t;;\n-\t-*)\n-\t\tusage\n-\t\t;;\n \t*)\n-\t\tbreak\n+\t\tusage # should not happen\n+\t\t;;\n \tesac\n \tshift\n done\n \n if [ \"$disabled\" = true ]; then\n-\techo \"clean.requireForce set and -n or -f not given; refusing to clean\"\n-\texit 1\n+\tdie \"clean.requireForce set and -n or -f not given; refusing to clean\"\n fi\n \n-case \"$ignored,$ignoredonly\" in\n-\t1,1) usage;;\n-esac\n+if [ \"$ignored,$ignoredonly\" = \"1,1\" ]; then\n+\tdie \"-x and -X cannot be set together\"\n+fi\n \n if [ -z \"$ignored\" ]; then\n \texcl=\"--exclude-per-directory=.gitignore\"\n-- \n1.5.3.5.1458.g2aa13-dirty\n\n"},{"id":"58004","messageId":"20071102160124.DB2992E3A@madism.org","threadId":"10595","inReplyTo":"1194016162-23599-4-git-send-email-madcoder@debian.org","subject":"[PATCH] Migrate git-clone to use git-parseopt(1)","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2007-11-02T15:58:03Z","receivedAt":"2007-11-02T15:58:03Z","isPatch":true,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"Signed-off-by: Pierre Habouzit <madcoder@debian.org>\n---\n git-clone.sh |  101 ++++++++++++++++++++++++++++++++-------------------------\n 1 files changed, 57 insertions(+), 44 deletions(-)\n\ndiff --git a/git-clone.sh b/git-clone.sh\nindex 0ea3c24..b30005d 100755\n--- a/git-clone.sh\n+++ b/git-clone.sh\n@@ -8,15 +8,35 @@\n # See git-sh-setup why.\n unset CDPATH\n \n+OPTIONS_SPEC=\"\\\n+git-clone [options] <repo> [<dir>]\n+--\n+n,no-checkout        don't create a checkout\n+bare                 create a bare repository\n+naked                create a bare repository\n+l,local              to clone from a local repository\n+no-hardlinks         don't use local hardlinks, always copy\n+s,shared             setup as a shared repository\n+template=            path to the template directory\n+q,quiet              be quiet\n+reference=           reference repository\n+o,origin=            use <name> instead of 'origin' to track upstream\n+u,upload-pack=       path to git-upload-pack on the remote\n+depth=               create a shallow clone of that depth\n+use-separate-remote  compatibility, do not use\n+no-separate-remote   compatibility, do not use\"\n+\n die() {\n \techo >&2 \"$@\"\n \texit 1\n }\n \n usage() {\n-\tdie \"Usage: $0 [--template=<template_directory>] [--reference <reference-repo>] [--bare] [-l [-s]] [-q] [-u <upload-pack>] [--origin <name>] [--depth <n>] [-n] <repo> [<dir>]\"\n+\texec \"$0\" -h\n }\n \n+eval `echo \"$OPTIONS_SPEC\" | git parseopt $PARSEOPT_OPTS -- \"$@\" || echo exit $?`\n+\n get_repo_base() {\n \t(\n \t\tcd \"`/bin/pwd`\" &&\n@@ -106,64 +126,57 @@ depth=\n no_progress=\n local_explicitly_asked_for=\n test -t 1 || no_progress=--no-progress\n-while\n-\tcase \"$#,$1\" in\n-\t0,*) break ;;\n-\t*,-n|*,--no|*,--no-|*,--no-c|*,--no-ch|*,--no-che|*,--no-chec|\\\n-\t*,--no-check|*,--no-checko|*,--no-checkou|*,--no-checkout)\n-\t  no_checkout=yes ;;\n-\t*,--na|*,--nak|*,--nake|*,--naked|\\\n-\t*,-b|*,--b|*,--ba|*,--bar|*,--bare) bare=yes ;;\n-\t*,-l|*,--l|*,--lo|*,--loc|*,--loca|*,--local)\n-\t  local_explicitly_asked_for=yes\n-\t  use_local_hardlink=yes ;;\n-\t*,--no-h|*,--no-ha|*,--no-har|*,--no-hard|*,--no-hardl|\\\n-\t*,--no-hardli|*,--no-hardlin|*,--no-hardlink|*,--no-hardlinks)\n-\t  use_local_hardlink=no ;;\n-        *,-s|*,--s|*,--sh|*,--sha|*,--shar|*,--share|*,--shared)\n-          local_shared=yes; ;;\n-\t1,--template) usage ;;\n-\t*,--template)\n+\n+while test $# != 0\n+do\n+\tcase \"$1\" in\n+\t-n|--no-checkout)\n+\t\tno_checkout=yes ;;\n+\t--naked|--bare)\n+\t\tbare=yes ;;\n+\t-l|--local)\n+\t\tlocal_explicitly_asked_for=yes\n+\t\tuse_local_hardlink=yes\n+\t\t;;\n+\t--no-hardlinks)\n+\t\tuse_local_hardlink=no ;;\n+\t-s|--shared)\n+\t\tlocal_shared=yes ;;\n+\t--template)\n \t\tshift; template=\"--template=$1\" ;;\n-\t*,--template=*)\n-\t  template=\"$1\" ;;\n-\t*,-q|*,--quiet) quiet=-q ;;\n-\t*,--use-separate-remote) ;;\n-\t*,--no-separate-remote)\n+\t-q|--quiet)\n+\t\tquiet=-q ;;\n+\t--use-separate-remote|--no-separate-remote)\n \t\tdie \"clones are always made with separate-remote layout\" ;;\n-\t1,--reference) usage ;;\n-\t*,--reference)\n+\t--reference)\n \t\tshift; reference=\"$1\" ;;\n-\t*,--reference=*)\n-\t\treference=`expr \"z$1\" : 'z--reference=\\(.*\\)'` ;;\n-\t*,-o|*,--or|*,--ori|*,--orig|*,--origi|*,--origin)\n-\t\tcase \"$2\" in\n+\t-o,--origin)\n+\t\tshift;\n+\t\tcase \"$1\" in\n \t\t'')\n \t\t    usage ;;\n \t\t*/*)\n-\t\t    die \"'$2' is not suitable for an origin name\"\n+\t\t    die \"'$1' is not suitable for an origin name\"\n \t\tesac\n-\t\tgit check-ref-format \"heads/$2\" ||\n-\t\t    die \"'$2' is not suitable for a branch name\"\n+\t\tgit check-ref-format \"heads/$1\" ||\n+\t\t    die \"'$1' 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\torigin=\"$1\"\n \t\t;;\n-\t1,-u|1,--upload-pack) usage ;;\n-\t*,-u|*,--upload-pack)\n+\t-u|--upload-pack)\n \t\tshift\n \t\tupload_pack=\"--upload-pack=$1\" ;;\n-\t*,--upload-pack=*)\n-\t\tupload_pack=--upload-pack=$(expr \"z$1\" : 'z-[^=]*=\\(.*\\)') ;;\n-\t1,--depth) usage;;\n-\t*,--depth)\n+\t--depth)\n+\t\tshift\n+\t\tdepth=\"--depth=$1\" ;;\n+\t--)\n \t\tshift\n-\t\tdepth=\"--depth=$1\";;\n-\t*,-*) usage ;;\n-\t*) break ;;\n+\t\tbreak ;;\n+\t*)\n+\t\tusage ;;\n \tesac\n-do\n \tshift\n done\n \n-- \n1.5.3.5.1458.g2aa13-dirty\n"}]}