diff options
author | Junio C Hamano <gitster@pobox.com> | 2024-02-08 16:22:03 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-02-08 16:22:03 -0800 |
commit | 952916f9e0d234ef4d0e1de0a4d8eae27ebfb16c (patch) | |
tree | 370e7fdc10a6d3a5eb18276731ddc394d4a4a564 | |
parent | 28b47452b30523b1be75f5d7b837504df79a78ff (diff) | |
parent | 7382497372f065fefe737333980a8146ede2955c (diff) | |
download | git-952916f9e0d234ef4d0e1de0a4d8eae27ebfb16c.tar.gz |
Merge branch 'rs/show-ref-incompatible-options' into maint-2.43
Code clean-up for sanity checking of command line options for "git
show-ref".
* rs/show-ref-incompatible-options:
show-ref: use die_for_incompatible_opt3()
-rw-r--r-- | builtin/show-ref.c | 6 | ||||
-rwxr-xr-x | t/t1403-show-ref.sh | 16 |
2 files changed, 12 insertions, 10 deletions
diff --git a/builtin/show-ref.c b/builtin/show-ref.c index 7aac525a87..59d2291cbf 100644 --- a/builtin/show-ref.c +++ b/builtin/show-ref.c @@ -315,9 +315,9 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, prefix, show_ref_options, show_ref_usage, 0); - if ((!!exclude_existing_opts.enabled + !!verify + !!exists) > 1) - die(_("only one of '%s', '%s' or '%s' can be given"), - "--exclude-existing", "--verify", "--exists"); + die_for_incompatible_opt3(exclude_existing_opts.enabled, "--exclude-existing", + verify, "--verify", + exists, "--exists"); if (exclude_existing_opts.enabled) return cmd_show_ref__exclude_existing(&exclude_existing_opts); diff --git a/t/t1403-show-ref.sh b/t/t1403-show-ref.sh index b50ae6fcf1..d477689e33 100755 --- a/t/t1403-show-ref.sh +++ b/t/t1403-show-ref.sh @@ -197,18 +197,20 @@ test_expect_success 'show-ref --verify with dangling ref' ' ' test_expect_success 'show-ref sub-modes are mutually exclusive' ' - cat >expect <<-EOF && - fatal: only one of ${SQ}--exclude-existing${SQ}, ${SQ}--verify${SQ} or ${SQ}--exists${SQ} can be given - EOF - test_must_fail git show-ref --verify --exclude-existing 2>err && - test_cmp expect err && + grep "verify" err && + grep "exclude-existing" err && + grep "cannot be used together" err && test_must_fail git show-ref --verify --exists 2>err && - test_cmp expect err && + grep "verify" err && + grep "exists" err && + grep "cannot be used together" err && test_must_fail git show-ref --exclude-existing --exists 2>err && - test_cmp expect err + grep "exclude-existing" err && + grep "exists" err && + grep "cannot be used together" err ' test_expect_success '--exists with existing reference' ' |