pull: use git-rev-parse --parseopt for option parsing

To enable unambiguous parsing of abbreviated options, bundled short options, separate form options and to provide consistent usage help, use git-rev-parse --parseopt for option parsing. With this, simplify the option parsing code. Signed-off-by: Paul Tan <pyokagan@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Paul Tan committed Jun 2, 2015 at 22:22 UTC e3b601da2af53cbb9a63e59113d524a8d946ea12
1 file changed +57 -40
git-pull.sh
+57 -40
@@ -4,13 +4,53 @@
4 #
5 # Fetch one or more remote refs and merge it/them into the current HEAD.
6
7 -USAGE='[-n | --no-stat] [--[no-]commit] [--[no-]squash] [--[no-]ff|--ff-only] [--[no-]rebase|--rebase=preserve] [-s strategy]... [<fetch-options>] <repo> <head>...'
8 -LONG_USAGE='Fetch one or more remote refs and integrate it/them with the current HEAD.'
7 SUBDIRECTORY_OK=Yes
10 -OPTIONS_SPEC=
8 +OPTIONS_KEEPDASHDASH=
9 +OPTIONS_STUCKLONG=Yes
10 +OPTIONS_SPEC="\
11 +git pull [options] [<repository> [<refspec>...]]
12 +
13 +Fetch one or more remote refs and integrate it/them with the current HEAD.
14 +--
15 +v,verbose be more verbose
16 +q,quiet be more quiet
17 +progress force progress reporting
18 +
19 + Options related to merging
20 +r,rebase?false|true|preserve incorporate changes by rebasing rather than merging
21 +n! do not show a diffstat at the end of the merge
22 +stat show a diffstat at the end of the merge
23 +summary (synonym to --stat)
24 +log?n add (at most <n>) entries from shortlog to merge commit message
25 +squash create a single commit instead of doing a merge
26 +commit perform a commit if the merge succeeds (default)
27 +e,edit edit message before committing
28 +ff allow fast-forward
29 +ff-only! abort if fast-forward is not possible
30 +verify-signatures verify that the named commit has a valid GPG signature
31 +s,strategy=strategy merge strategy to use
32 +X,strategy-option=option option for selected merge strategy
33 +S,gpg-sign?key-id GPG sign commit
34 +
35 + Options related to fetching
36 +all fetch from all remotes
37 +a,append append to .git/FETCH_HEAD instead of overwriting
38 +upload-pack=path path to upload pack on remote end
39 +f,force force overwrite of local branch
40 +t,tags fetch all tags and associated objects
41 +p,prune prune remote-tracking branches no longer on remote
42 +recurse-submodules?on-demand control recursive fetching of submodules
43 +dry-run dry run
44 +k,keep keep downloaded pack
45 +depth=depth deepen history of shallow clone
46 +unshallow convert to a complete repository
47 +update-shallow accept refs that update .git/shallow
48 +refmap=refmap specify fetch refmap
49 +"
50 +test $# -gt 0 && args="$*"
51 . git-sh-setup
52 . git-sh-i18n
13 -set_reflog_action "pull${1+ $*}"
53 +set_reflog_action "pull${args+ $args}"
54 require_work_tree_exists
55 cd_to_toplevel
56
@@ -87,17 +127,17 @@ do
127 diffstat=--stat ;;
128 --log|--log=*|--no-log)
129 log_arg="$1" ;;
90 - --no-c|--no-co|--no-com|--no-comm|--no-commi|--no-commit)
130 + --no-commit)
131 no_commit=--no-commit ;;
92 - --c|--co|--com|--comm|--commi|--commit)
132 + --commit)
133 no_commit=--commit ;;
134 -e|--edit)
135 edit=--edit ;;
136 --no-edit)
137 edit=--no-edit ;;
98 - --sq|--squ|--squa|--squas|--squash)
138 + --squash)
139 squash=--squash ;;
100 - --no-sq|--no-squ|--no-squa|--no-squas|--no-squash)
140 + --no-squash)
141 squash=--no-squash ;;
142 --ff)
143 no_ff=--ff ;;
@@ -105,39 +145,19 @@ do
145 no_ff=--no-ff ;;
146 --ff-only)
147 ff_only=--ff-only ;;
108 - -s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\
109 - --strateg=*|--strategy=*|\
110 - -s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy)
111 - case "$#,$1" in
112 - *,*=*)
113 - strategy=$(expr "z$1" : 'z-[^=]*=\(.*\)') ;;
114 - 1,*)
115 - usage ;;
116 - *)
117 - strategy="$2"
118 - shift ;;
119 - esac
120 - strategy_args="${strategy_args}-s $strategy "
148 + -s*|--strategy=*)
149 + strategy_args="$strategy_args $1"
150 ;;
122 - -X*)
123 - case "$#,$1" in
124 - 1,-X)
125 - usage ;;
126 - *,-X)
127 - xx="-X $(git rev-parse --sq-quote "$2")"
128 - shift ;;
129 - *,*)
130 - xx=$(git rev-parse --sq-quote "$1") ;;
131 - esac
132 - merge_args="$merge_args$xx "
151 + -X*|--strategy-option=*)
152 + merge_args="$merge_args $(git rev-parse --sq-quote "$1")"
153 ;;
134 - -r=*|--r=*|--re=*|--reb=*|--reba=*|--rebas=*|--rebase=*)
154 + -r*|--rebase=*)
155 rebase="${1#*=}"
156 ;;
137 - -r|--r|--re|--reb|--reba|--rebas|--rebase)
157 + --rebase)
158 rebase=true
159 ;;
140 - --no-r|--no-re|--no-reb|--no-reba|--no-rebas|--no-rebase)
160 + --no-rebase)
161 rebase=false
162 ;;
163 --recurse-submodules)
@@ -164,7 +184,7 @@ do
184 -S*)
185 gpg_sign_args=$(git rev-parse --sq-quote "$1")
186 ;;
167 - --d|--dr|--dry|--dry-|--dry-r|--dry-ru|--dry-run)
187 + --dry-run)
188 dry_run=--dry-run
189 ;;
190 --all|--no-all)
@@ -196,11 +216,8 @@ do
216 shift
217 break
218 ;;
199 - -*)
200 - usage
201 - ;;
219 *)
203 - break
220 + usage
221 ;;
222 esac
223 shift