@matheusbsbs / matheus-bagliano / commits / 943625998b
Fork 0

Migrate git-clone to use git-rev-parse --parseopt

Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Pierre Habouzit committed Nov 4, 2007 at 11:30 UTC 943625998b43ae7b7a4faf840951f0cefb28dc33
1 file changed +56 -45
git-clone.sh
+56 -45
@@ -8,15 +8,36 @@
8 # See git-sh-setup why.
9 unset CDPATH
10
11 +OPTIONS_SPEC="\
12 +git-clone [options] [--] <repo> [<dir>]
13 +--
14 +n,no-checkout don't create a checkout
15 +bare create a bare repository
16 +naked create a bare repository
17 +l,local to clone from a local repository
18 +no-hardlinks don't use local hardlinks, always copy
19 +s,shared setup as a shared repository
20 +template= path to the template directory
21 +q,quiet be quiet
22 +reference= reference repository
23 +o,origin= use <name> instead of 'origin' to track upstream
24 +u,upload-pack= path to git-upload-pack on the remote
25 +depth= create a shallow clone of that depth
26 +
27 +use-separate-remote compatibility, do not use
28 +no-separate-remote compatibility, do not use"
29 +
30 die() {
31 echo >&2 "$@"
32 exit 1
33 }
34
35 usage() {
17 - die "Usage: $0 [--template=<template_directory>] [--reference <reference-repo>] [--bare] [-l [-s]] [-q] [-u <upload-pack>] [--origin <name>] [--depth <n>] [-n] [--] <repo> [<dir>]"
36 + exec "$0" -h
37 }
38
39 +eval `echo "$OPTIONS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?`
40 +
41 get_repo_base() {
42 (
43 cd "`/bin/pwd`" &&
@@ -106,67 +127,57 @@ depth=
127 no_progress=
128 local_explicitly_asked_for=
129 test -t 1 || no_progress=--no-progress
109 -while
110 - case "$#,$1" in
111 - 0,*) break ;;
112 - *,-n|*,--no|*,--no-|*,--no-c|*,--no-ch|*,--no-che|*,--no-chec|\
113 - *,--no-check|*,--no-checko|*,--no-checkou|*,--no-checkout)
114 - no_checkout=yes ;;
115 - *,--na|*,--nak|*,--nake|*,--naked|\
116 - *,-b|*,--b|*,--ba|*,--bar|*,--bare) bare=yes ;;
117 - *,-l|*,--l|*,--lo|*,--loc|*,--loca|*,--local)
118 - local_explicitly_asked_for=yes
119 - use_local_hardlink=yes ;;
120 - *,--no-h|*,--no-ha|*,--no-har|*,--no-hard|*,--no-hardl|\
121 - *,--no-hardli|*,--no-hardlin|*,--no-hardlink|*,--no-hardlinks)
122 - use_local_hardlink=no ;;
123 - *,-s|*,--s|*,--sh|*,--sha|*,--shar|*,--share|*,--shared)
124 - local_shared=yes; ;;
125 - 1,--template) usage ;;
126 - *,--template)
130 +
131 +while test $# != 0
132 +do
133 + case "$1" in
134 + -n|--no-checkout)
135 + no_checkout=yes ;;
136 + --naked|--bare)
137 + bare=yes ;;
138 + -l|--local)
139 + local_explicitly_asked_for=yes
140 + use_local_hardlink=yes
141 + ;;
142 + --no-hardlinks)
143 + use_local_hardlink=no ;;
144 + -s|--shared)
145 + local_shared=yes ;;
146 + --template)
147 shift; template="--template=$1" ;;
128 - *,--template=*)
129 - template="$1" ;;
130 - *,-q|*,--quiet) quiet=-q ;;
131 - *,--use-separate-remote) ;;
132 - *,--no-separate-remote)
148 + -q|--quiet)
149 + quiet=-q ;;
150 + --use-separate-remote|--no-separate-remote)
151 die "clones are always made with separate-remote layout" ;;
134 - 1,--reference) usage ;;
135 - *,--reference)
152 + --reference)
153 shift; reference="$1" ;;
137 - *,--reference=*)
138 - reference=`expr "z$1" : 'z--reference=\(.*\)'` ;;
139 - *,-o|*,--or|*,--ori|*,--orig|*,--origi|*,--origin)
140 - case "$2" in
154 + -o,--origin)
155 + shift;
156 + case "$1" in
157 '')
158 usage ;;
159 */*)
144 - die "'$2' is not suitable for an origin name"
160 + die "'$1' is not suitable for an origin name"
161 esac
146 - git check-ref-format "heads/$2" ||
147 - die "'$2' is not suitable for a branch name"
162 + git check-ref-format "heads/$1" ||
163 + die "'$1' is not suitable for a branch name"
164 test -z "$origin_override" ||
165 die "Do not give more than one --origin options."
166 origin_override=yes
151 - origin="$2"; shift
167 + origin="$1"
168 ;;
153 - 1,-u|1,--upload-pack) usage ;;
154 - *,-u|*,--upload-pack)
169 + -u|--upload-pack)
170 shift
171 upload_pack="--upload-pack=$1" ;;
157 - *,--upload-pack=*)
158 - upload_pack=--upload-pack=$(expr "z$1" : 'z-[^=]*=\(.*\)') ;;
159 - 1,--depth) usage;;
160 - *,--depth)
172 + --depth)
173 shift
162 - depth="--depth=$1";;
163 - *,--)
174 + depth="--depth=$1" ;;
175 + --)
176 shift
177 break ;;
166 - *,-*) usage ;;
167 - *) break ;;
178 + *)
179 + usage ;;
180 esac
169 -do
181 shift
182 done
183