Skip to content

Commit 39e4773

Browse files
committed
Merge branch 'js/spell-out-options-in-tests'
The tests have been updated not to rely on the abbreviated option names the parse-options API offers, to protect us from an abbreviated form of an option that used to be unique within the command getting non-unique when a new option that share the same prefix is added. * js/spell-out-options-in-tests: tests: disallow the use of abbreviated options (by default) tests (pack-objects): use the full, unabbreviated `--revs` option tests (status): spell out the `--find-renames` option in full tests (push): do not abbreviate the `--follow-tags` option t5531: avoid using an abbreviated option t7810: do not abbreviate `--no-exclude-standard` nor `--invert-match` tests (rebase): spell out the `--force-rebase` option tests (rebase): spell out the `--keep-empty` option
2 parents 87e20f8 + b02e7d5 commit 39e4773

12 files changed

+75
-43
lines changed

parse-options.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include "color.h"
77
#include "utf8.h"
88

9+
static int disallow_abbreviated_options;
10+
911
#define OPT_SHORT 1
1012
#define OPT_UNSET 2
1113

@@ -344,6 +346,10 @@ static enum parse_opt_result parse_long_opt(
344346
return get_value(p, options, all_opts, flags ^ opt_flags);
345347
}
346348

349+
if (disallow_abbreviated_options && (ambiguous_option || abbrev_option))
350+
die("disallowed abbreviated or ambiguous option '%.*s'",
351+
(int)(arg_end - arg), arg);
352+
347353
if (ambiguous_option) {
348354
error(_("ambiguous option: %s "
349355
"(could be --%s%s or --%s%s)"),
@@ -708,6 +714,9 @@ int parse_options(int argc, const char **argv, const char *prefix,
708714
{
709715
struct parse_opt_ctx_t ctx;
710716

717+
disallow_abbreviated_options =
718+
git_env_bool("GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS", 0);
719+
711720
parse_options_start(&ctx, argc, argv, prefix, options, flags);
712721
switch (parse_options_step(&ctx, options, usagestr)) {
713722
case PARSE_OPT_HELP:

t/README

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,10 @@ GIT_TEST_SIDEBAND_ALL=<boolean>, when true, overrides the
402402
fetch-pack to not request sideband-all (even if the server advertises
403403
sideband-all).
404404

405+
GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=<boolean>, when true (which is
406+
the default when running tests), errors out when an abbreviated option
407+
is used.
408+
405409
Naming Tests
406410
------------
407411

t/t0040-parse-options.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,20 +203,24 @@ file: (not set)
203203
EOF
204204

205205
test_expect_success 'unambiguously abbreviated option' '
206+
GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=false \
206207
test-tool parse-options --int 2 --boolean --no-bo >output 2>output.err &&
207208
test_must_be_empty output.err &&
208209
test_cmp expect output
209210
'
210211

211212
test_expect_success 'unambiguously abbreviated option with "="' '
213+
GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=false \
212214
test-tool parse-options --expect="integer: 2" --int=2
213215
'
214216

215217
test_expect_success 'ambiguously abbreviated option' '
216-
test_expect_code 129 test-tool parse-options --strin 123
218+
test_expect_code 129 env GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=false \
219+
test-tool parse-options --strin 123
217220
'
218221

219222
test_expect_success 'non ambiguous option (after two options it abbreviates)' '
223+
GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=false \
220224
test-tool parse-options --expect="string: 123" --st 123
221225
'
222226

@@ -325,6 +329,7 @@ file: (not set)
325329
EOF
326330

327331
test_expect_success 'negation of OPT_NONEG flags is not ambiguous' '
332+
GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=false \
328333
test-tool parse-options --no-ambig >output 2>output.err &&
329334
test_must_be_empty output.err &&
330335
test_cmp expect output
@@ -370,4 +375,11 @@ test_expect_success '--no-verbose resets multiple verbose to 0' '
370375
test-tool parse-options --expect="verbose: 0" -v -v -v --no-verbose
371376
'
372377

378+
test_expect_success 'GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS works' '
379+
GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=false \
380+
test-tool parse-options --ye &&
381+
test_must_fail env GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=true \
382+
test-tool parse-options --ye
383+
'
384+
373385
test_done

t/t3415-rebase-autosquash.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ test_expect_success 'autosquash with empty custom instructionFormat' '
277277
(
278278
set_cat_todo_editor &&
279279
test_must_fail git -c rebase.instructionFormat= \
280-
rebase --autosquash --force -i HEAD^ >actual &&
280+
rebase --autosquash --force-rebase -i HEAD^ >actual &&
281281
git log -1 --format="pick %h %s" >expect &&
282282
test_cmp expect actual
283283
)

t/t3430-rebase-merges.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ test_expect_success 'root commits' '
271271
EOF
272272
test_config sequence.editor \""$PWD"/replace-editor.sh\" &&
273273
test_tick &&
274-
git rebase -i --force --root -r &&
274+
git rebase -i --force-rebase --root -r &&
275275
test "Parsnip" = "$(git show -s --format=%an HEAD^)" &&
276276
test $(git rev-parse second-root^0) != $(git rev-parse HEAD^) &&
277277
test $(git rev-parse second-root:second-root.t) = \
@@ -364,7 +364,7 @@ test_expect_success 'octopus merges' '
364364
test_cmp_rev HEAD $before &&
365365
366366
test_tick &&
367-
git rebase -i --force -r HEAD^^ &&
367+
git rebase -i --force-rebase -r HEAD^^ &&
368368
test "Hank" = "$(git show -s --format=%an HEAD)" &&
369369
test "$before" != $(git rev-parse HEAD) &&
370370
test_cmp_graph HEAD^^.. <<-\EOF

t/t5317-pack-objects-filter-objects.sh

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ test_expect_success 'verify blob count in normal packfile' '
2525
awk -f print_2.awk ls_files_result |
2626
sort >expected &&
2727
28-
git -C r1 pack-objects --rev --stdout >all.pack <<-EOF &&
28+
git -C r1 pack-objects --revs --stdout >all.pack <<-EOF &&
2929
HEAD
3030
EOF
3131
git -C r1 index-pack ../all.pack &&
@@ -39,7 +39,7 @@ test_expect_success 'verify blob count in normal packfile' '
3939
'
4040

4141
test_expect_success 'verify blob:none packfile has no blobs' '
42-
git -C r1 pack-objects --rev --stdout --filter=blob:none >filter.pack <<-EOF &&
42+
git -C r1 pack-objects --revs --stdout --filter=blob:none >filter.pack <<-EOF &&
4343
HEAD
4444
EOF
4545
git -C r1 index-pack ../filter.pack &&
@@ -74,7 +74,7 @@ test_expect_success 'get an error for missing tree object' '
7474
git -C r5 commit -m "foo" &&
7575
del=$(git -C r5 rev-parse HEAD^{tree} | sed "s|..|&/|") &&
7676
rm r5/.git/objects/$del &&
77-
test_must_fail git -C r5 pack-objects --rev --stdout 2>bad_tree <<-EOF &&
77+
test_must_fail git -C r5 pack-objects --revs --stdout 2>bad_tree <<-EOF &&
7878
HEAD
7979
EOF
8080
grep "bad tree object" bad_tree
@@ -88,7 +88,7 @@ test_expect_success 'setup for tests of tree:0' '
8888
'
8989

9090
test_expect_success 'verify tree:0 packfile has no blobs or trees' '
91-
git -C r1 pack-objects --rev --stdout --filter=tree:0 >commitsonly.pack <<-EOF &&
91+
git -C r1 pack-objects --revs --stdout --filter=tree:0 >commitsonly.pack <<-EOF &&
9292
HEAD
9393
EOF
9494
git -C r1 index-pack ../commitsonly.pack &&
@@ -98,7 +98,7 @@ test_expect_success 'verify tree:0 packfile has no blobs or trees' '
9898

9999
test_expect_success 'grab tree directly when using tree:0' '
100100
# We should get the tree specified directly but not its blobs or subtrees.
101-
git -C r1 pack-objects --rev --stdout --filter=tree:0 >commitsonly.pack <<-EOF &&
101+
git -C r1 pack-objects --revs --stdout --filter=tree:0 >commitsonly.pack <<-EOF &&
102102
HEAD:
103103
EOF
104104
git -C r1 index-pack ../commitsonly.pack &&
@@ -128,7 +128,7 @@ test_expect_success 'verify blob count in normal packfile' '
128128
awk -f print_2.awk ls_files_result |
129129
sort >expected &&
130130
131-
git -C r2 pack-objects --rev --stdout >all.pack <<-EOF &&
131+
git -C r2 pack-objects --revs --stdout >all.pack <<-EOF &&
132132
HEAD
133133
EOF
134134
git -C r2 index-pack ../all.pack &&
@@ -142,7 +142,7 @@ test_expect_success 'verify blob count in normal packfile' '
142142
'
143143

144144
test_expect_success 'verify blob:limit=500 omits all blobs' '
145-
git -C r2 pack-objects --rev --stdout --filter=blob:limit=500 >filter.pack <<-EOF &&
145+
git -C r2 pack-objects --revs --stdout --filter=blob:limit=500 >filter.pack <<-EOF &&
146146
HEAD
147147
EOF
148148
git -C r2 index-pack ../filter.pack &&
@@ -157,7 +157,7 @@ test_expect_success 'verify blob:limit=500 omits all blobs' '
157157
'
158158

159159
test_expect_success 'verify blob:limit=1000' '
160-
git -C r2 pack-objects --rev --stdout --filter=blob:limit=1000 >filter.pack <<-EOF &&
160+
git -C r2 pack-objects --revs --stdout --filter=blob:limit=1000 >filter.pack <<-EOF &&
161161
HEAD
162162
EOF
163163
git -C r2 index-pack ../filter.pack &&
@@ -176,7 +176,7 @@ test_expect_success 'verify blob:limit=1001' '
176176
awk -f print_2.awk ls_files_result |
177177
sort >expected &&
178178
179-
git -C r2 pack-objects --rev --stdout --filter=blob:limit=1001 >filter.pack <<-EOF &&
179+
git -C r2 pack-objects --revs --stdout --filter=blob:limit=1001 >filter.pack <<-EOF &&
180180
HEAD
181181
EOF
182182
git -C r2 index-pack ../filter.pack &&
@@ -194,7 +194,7 @@ test_expect_success 'verify blob:limit=10001' '
194194
awk -f print_2.awk ls_files_result |
195195
sort >expected &&
196196
197-
git -C r2 pack-objects --rev --stdout --filter=blob:limit=10001 >filter.pack <<-EOF &&
197+
git -C r2 pack-objects --revs --stdout --filter=blob:limit=10001 >filter.pack <<-EOF &&
198198
HEAD
199199
EOF
200200
git -C r2 index-pack ../filter.pack &&
@@ -212,7 +212,7 @@ test_expect_success 'verify blob:limit=1k' '
212212
awk -f print_2.awk ls_files_result |
213213
sort >expected &&
214214
215-
git -C r2 pack-objects --rev --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
215+
git -C r2 pack-objects --revs --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
216216
HEAD
217217
EOF
218218
git -C r2 index-pack ../filter.pack &&
@@ -230,7 +230,7 @@ test_expect_success 'verify explicitly specifying oversized blob in input' '
230230
awk -f print_2.awk ls_files_result |
231231
sort >expected &&
232232
233-
git -C r2 pack-objects --rev --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
233+
git -C r2 pack-objects --revs --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
234234
HEAD
235235
$(git -C r2 rev-parse HEAD:large.10000)
236236
EOF
@@ -249,7 +249,7 @@ test_expect_success 'verify blob:limit=1m' '
249249
awk -f print_2.awk ls_files_result |
250250
sort >expected &&
251251
252-
git -C r2 pack-objects --rev --stdout --filter=blob:limit=1m >filter.pack <<-EOF &&
252+
git -C r2 pack-objects --revs --stdout --filter=blob:limit=1m >filter.pack <<-EOF &&
253253
HEAD
254254
EOF
255255
git -C r2 index-pack ../filter.pack &&
@@ -302,7 +302,7 @@ test_expect_success 'verify blob count in normal packfile' '
302302
awk -f print_2.awk ls_files_result |
303303
sort >expected &&
304304
305-
git -C r3 pack-objects --rev --stdout >all.pack <<-EOF &&
305+
git -C r3 pack-objects --revs --stdout >all.pack <<-EOF &&
306306
HEAD
307307
EOF
308308
git -C r3 index-pack ../all.pack &&
@@ -320,7 +320,7 @@ test_expect_success 'verify sparse:path=pattern1' '
320320
awk -f print_2.awk ls_files_result |
321321
sort >expected &&
322322
323-
git -C r3 pack-objects --rev --stdout --filter=sparse:path=../pattern1 >filter.pack <<-EOF &&
323+
git -C r3 pack-objects --revs --stdout --filter=sparse:path=../pattern1 >filter.pack <<-EOF &&
324324
HEAD
325325
EOF
326326
git -C r3 index-pack ../filter.pack &&
@@ -352,7 +352,7 @@ test_expect_success 'verify sparse:path=pattern2' '
352352
awk -f print_2.awk ls_files_result |
353353
sort >expected &&
354354
355-
git -C r3 pack-objects --rev --stdout --filter=sparse:path=../pattern2 >filter.pack <<-EOF &&
355+
git -C r3 pack-objects --revs --stdout --filter=sparse:path=../pattern2 >filter.pack <<-EOF &&
356356
HEAD
357357
EOF
358358
git -C r3 index-pack ../filter.pack &&
@@ -404,7 +404,7 @@ test_expect_success 'verify blob count in normal packfile' '
404404
awk -f print_2.awk ls_files_result |
405405
sort >expected &&
406406
407-
git -C r4 pack-objects --rev --stdout >all.pack <<-EOF &&
407+
git -C r4 pack-objects --revs --stdout >all.pack <<-EOF &&
408408
HEAD
409409
EOF
410410
git -C r4 index-pack ../all.pack &&
@@ -423,7 +423,7 @@ test_expect_success 'verify sparse:oid=OID' '
423423
sort >expected &&
424424
425425
oid=$(git -C r4 ls-files -s pattern | awk -f print_2.awk) &&
426-
git -C r4 pack-objects --rev --stdout --filter=sparse:oid=$oid >filter.pack <<-EOF &&
426+
git -C r4 pack-objects --revs --stdout --filter=sparse:oid=$oid >filter.pack <<-EOF &&
427427
HEAD
428428
EOF
429429
git -C r4 index-pack ../filter.pack &&
@@ -441,7 +441,7 @@ test_expect_success 'verify sparse:oid=oid-ish' '
441441
awk -f print_2.awk ls_files_result |
442442
sort >expected &&
443443
444-
git -C r4 pack-objects --rev --stdout --filter=sparse:oid=master:pattern >filter.pack <<-EOF &&
444+
git -C r4 pack-objects --revs --stdout --filter=sparse:oid=master:pattern >filter.pack <<-EOF &&
445445
HEAD
446446
EOF
447447
git -C r4 index-pack ../filter.pack &&
@@ -470,19 +470,19 @@ test_expect_success 'setup r1 - delete loose blobs' '
470470
'
471471

472472
test_expect_success 'verify pack-objects fails w/ missing objects' '
473-
test_must_fail git -C r1 pack-objects --rev --stdout >miss.pack <<-EOF
473+
test_must_fail git -C r1 pack-objects --revs --stdout >miss.pack <<-EOF
474474
HEAD
475475
EOF
476476
'
477477

478478
test_expect_success 'verify pack-objects fails w/ --missing=error' '
479-
test_must_fail git -C r1 pack-objects --rev --stdout --missing=error >miss.pack <<-EOF
479+
test_must_fail git -C r1 pack-objects --revs --stdout --missing=error >miss.pack <<-EOF
480480
HEAD
481481
EOF
482482
'
483483

484484
test_expect_success 'verify pack-objects w/ --missing=allow-any' '
485-
git -C r1 pack-objects --rev --stdout --missing=allow-any >miss.pack <<-EOF
485+
git -C r1 pack-objects --revs --stdout --missing=allow-any >miss.pack <<-EOF
486486
HEAD
487487
EOF
488488
'

t/t5407-post-rewrite-hook.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ test_expect_success 'git rebase -m --skip' '
131131
test_expect_success 'git rebase with implicit use of interactive backend' '
132132
git reset --hard D &&
133133
clear_hook_input &&
134-
test_must_fail git rebase --keep --onto A B &&
134+
test_must_fail git rebase --keep-empty --onto A B &&
135135
echo C > foo &&
136136
git add foo &&
137137
git rebase --continue &&
@@ -146,7 +146,7 @@ test_expect_success 'git rebase with implicit use of interactive backend' '
146146
test_expect_success 'git rebase --skip with implicit use of interactive backend' '
147147
git reset --hard D &&
148148
clear_hook_input &&
149-
test_must_fail git rebase --keep --onto A B &&
149+
test_must_fail git rebase --keep-empty --onto A B &&
150150
test_must_fail git rebase --skip &&
151151
echo D > foo &&
152152
git add foo &&

t/t5516-fetch-push.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,7 @@ test_expect_success 'push does not follow tags by default' '
13821382
test_cmp expect actual
13831383
'
13841384

1385-
test_expect_success 'push --follow-tag only pushes relevant tags' '
1385+
test_expect_success 'push --follow-tags only pushes relevant tags' '
13861386
mk_test testrepo heads/master &&
13871387
rm -fr src dst &&
13881388
git init src &&
@@ -1396,7 +1396,7 @@ test_expect_success 'push --follow-tag only pushes relevant tags' '
13961396
git tag -m "future" future &&
13971397
git checkout master &&
13981398
git for-each-ref refs/heads/master refs/tags/tag >../expect &&
1399-
git push --follow-tag ../dst master
1399+
git push --follow-tags ../dst master
14001400
) &&
14011401
(
14021402
cd dst &&

t/t5531-deep-submodule-push.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ test_expect_success 'push succeeds if submodule has no remote and is on the firs
363363
) &&
364364
git add b &&
365365
git commit -m "added submodule" &&
366-
git push --recurse-submodule=check origin master
366+
git push --recurse-submodules=check origin master
367367
)
368368
'
369369

t/t7525-status-rename.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ test_expect_success 'status score=100%' '
8484
test_i18ngrep "deleted:" actual &&
8585
test_i18ngrep "new file:" actual &&
8686
87-
git status --find-rename=100% >actual &&
87+
git status --find-renames=100% >actual &&
8888
test_i18ngrep "deleted:" actual &&
8989
test_i18ngrep "new file:" actual
9090
'
@@ -93,19 +93,19 @@ test_expect_success 'status score=01%' '
9393
git status -M=01% >actual &&
9494
test_i18ngrep "renamed:" actual &&
9595
96-
git status --find-rename=01% >actual &&
96+
git status --find-renames=01% >actual &&
9797
test_i18ngrep "renamed:" actual
9898
'
9999

100-
test_expect_success 'copies not overridden by find-rename' '
100+
test_expect_success 'copies not overridden by find-renames' '
101101
cp renamed copy &&
102102
git add copy &&
103103
104104
git -c status.renames=copies status -M=01% >actual &&
105105
test_i18ngrep "copied:" actual &&
106106
test_i18ngrep "renamed:" actual &&
107107
108-
git -c status.renames=copies status --find-rename=01% >actual &&
108+
git -c status.renames=copies status --find-renames=01% >actual &&
109109
test_i18ngrep "copied:" actual &&
110110
test_i18ngrep "renamed:" actual
111111
'

0 commit comments

Comments
 (0)