Skip to content

Commit e3b601d

Browse files
pyokagangitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent eb2a8d9 commit e3b601d

File tree

1 file changed

+57
-40
lines changed

1 file changed

+57
-40
lines changed

git-pull.sh

Lines changed: 57 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,53 @@
44
#
55
# Fetch one or more remote refs and merge it/them into the current HEAD.
66

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.'
97
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="$*"
1151
. git-sh-setup
1252
. git-sh-i18n
13-
set_reflog_action "pull${1+ $*}"
53+
set_reflog_action "pull${args+ $args}"
1454
require_work_tree_exists
1555
cd_to_toplevel
1656

@@ -87,57 +127,37 @@ do
87127
diffstat=--stat ;;
88128
--log|--log=*|--no-log)
89129
log_arg="$1" ;;
90-
--no-c|--no-co|--no-com|--no-comm|--no-commi|--no-commit)
130+
--no-commit)
91131
no_commit=--no-commit ;;
92-
--c|--co|--com|--comm|--commi|--commit)
132+
--commit)
93133
no_commit=--commit ;;
94134
-e|--edit)
95135
edit=--edit ;;
96136
--no-edit)
97137
edit=--no-edit ;;
98-
--sq|--squ|--squa|--squas|--squash)
138+
--squash)
99139
squash=--squash ;;
100-
--no-sq|--no-squ|--no-squa|--no-squas|--no-squash)
140+
--no-squash)
101141
squash=--no-squash ;;
102142
--ff)
103143
no_ff=--ff ;;
104144
--no-ff)
105145
no_ff=--no-ff ;;
106146
--ff-only)
107147
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"
121150
;;
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")"
133153
;;
134-
-r=*|--r=*|--re=*|--reb=*|--reba=*|--rebas=*|--rebase=*)
154+
-r*|--rebase=*)
135155
rebase="${1#*=}"
136156
;;
137-
-r|--r|--re|--reb|--reba|--rebas|--rebase)
157+
--rebase)
138158
rebase=true
139159
;;
140-
--no-r|--no-re|--no-reb|--no-reba|--no-rebas|--no-rebase)
160+
--no-rebase)
141161
rebase=false
142162
;;
143163
--recurse-submodules)
@@ -164,7 +184,7 @@ do
164184
-S*)
165185
gpg_sign_args=$(git rev-parse --sq-quote "$1")
166186
;;
167-
--d|--dr|--dry|--dry-|--dry-r|--dry-ru|--dry-run)
187+
--dry-run)
168188
dry_run=--dry-run
169189
;;
170190
--all|--no-all)
@@ -196,11 +216,8 @@ do
196216
shift
197217
break
198218
;;
199-
-*)
200-
usage
201-
;;
202219
*)
203-
break
220+
usage
204221
;;
205222
esac
206223
shift

0 commit comments

Comments
 (0)