Skip to content

Commit 7382497

Browse files
rscharfegitster
authored andcommitted
show-ref: use die_for_incompatible_opt3()
Use the standard message for reporting the use of multiple mutually exclusive options by calling die_for_incompatible_opt3() instead of rolling our own. This has the benefits of showing only the actually given options, reducing the number of strings to translate and making the UI slightly more consistent. Adjust the test to no longer insist on a specific order of the reported options, as this implementation detail does not affect the usefulness of the error message. Reported-by: Eric Sunshine <[email protected]> Signed-off-by: René Scharfe <[email protected]> Reviewed-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 564d025 commit 7382497

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

builtin/show-ref.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,9 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)
315315
argc = parse_options(argc, argv, prefix, show_ref_options,
316316
show_ref_usage, 0);
317317

318-
if ((!!exclude_existing_opts.enabled + !!verify + !!exists) > 1)
319-
die(_("only one of '%s', '%s' or '%s' can be given"),
320-
"--exclude-existing", "--verify", "--exists");
318+
die_for_incompatible_opt3(exclude_existing_opts.enabled, "--exclude-existing",
319+
verify, "--verify",
320+
exists, "--exists");
321321

322322
if (exclude_existing_opts.enabled)
323323
return cmd_show_ref__exclude_existing(&exclude_existing_opts);

t/t1403-show-ref.sh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,18 +197,20 @@ test_expect_success 'show-ref --verify with dangling ref' '
197197
'
198198

199199
test_expect_success 'show-ref sub-modes are mutually exclusive' '
200-
cat >expect <<-EOF &&
201-
fatal: only one of ${SQ}--exclude-existing${SQ}, ${SQ}--verify${SQ} or ${SQ}--exists${SQ} can be given
202-
EOF
203-
204200
test_must_fail git show-ref --verify --exclude-existing 2>err &&
205-
test_cmp expect err &&
201+
grep "verify" err &&
202+
grep "exclude-existing" err &&
203+
grep "cannot be used together" err &&
206204
207205
test_must_fail git show-ref --verify --exists 2>err &&
208-
test_cmp expect err &&
206+
grep "verify" err &&
207+
grep "exists" err &&
208+
grep "cannot be used together" err &&
209209
210210
test_must_fail git show-ref --exclude-existing --exists 2>err &&
211-
test_cmp expect err
211+
grep "exclude-existing" err &&
212+
grep "exists" err &&
213+
grep "cannot be used together" err
212214
'
213215

214216
test_expect_success '--exists with existing reference' '

0 commit comments

Comments
 (0)