Skip to content

Commit 3c8f932

Browse files
committed
Merge branch 'rs/incompatible-options-messages'
Clean-up code that handles combinations of incompatible options. * rs/incompatible-options-messages: worktree: simplify incompatibility message for --orphan and commit-ish worktree: standardize incompatibility messages clean: factorize incompatibility message revision, rev-parse: factorize incompatibility messages about - -exclude-hidden revision: use die_for_incompatible_opt3() for - -graph/--reverse/--walk-reflogs repack: use die_for_incompatible_opt3() for -A/-k/--cruft push: use die_for_incompatible_opt4() for - -delete/--tags/--all/--mirror
2 parents c4bf868 + 792b862 commit 3c8f932

File tree

9 files changed

+46
-51
lines changed

9 files changed

+46
-51
lines changed

builtin/clean.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
971971
dir.flags |= DIR_SHOW_OTHER_DIRECTORIES;
972972

973973
if (ignored && ignored_only)
974-
die(_("-x and -X cannot be used together"));
974+
die(_("options '%s' and '%s' cannot be used together"), "-x", "-X");
975975
if (!ignored)
976976
setup_standard_excludes(&dir);
977977
if (ignored_only)

builtin/push.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -639,8 +639,10 @@ int cmd_push(int argc, const char **argv, const char *prefix)
639639
: &push_options_config);
640640
set_push_cert_flags(&flags, push_cert);
641641

642-
if (deleterefs && (tags || (flags & (TRANSPORT_PUSH_ALL | TRANSPORT_PUSH_MIRROR))))
643-
die(_("options '%s' and '%s' cannot be used together"), "--delete", "--all/--branches/--mirror/--tags");
642+
die_for_incompatible_opt4(deleterefs, "--delete",
643+
tags, "--tags",
644+
flags & TRANSPORT_PUSH_ALL, "--all/--branches",
645+
flags & TRANSPORT_PUSH_MIRROR, "--mirror");
644646
if (deleterefs && argc < 2)
645647
die(_("--delete doesn't make sense without any refs"));
646648

@@ -677,19 +679,13 @@ int cmd_push(int argc, const char **argv, const char *prefix)
677679
flags |= (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE);
678680

679681
if (flags & TRANSPORT_PUSH_ALL) {
680-
if (tags)
681-
die(_("options '%s' and '%s' cannot be used together"), "--all", "--tags");
682682
if (argc >= 2)
683683
die(_("--all can't be combined with refspecs"));
684684
}
685685
if (flags & TRANSPORT_PUSH_MIRROR) {
686-
if (tags)
687-
die(_("options '%s' and '%s' cannot be used together"), "--mirror", "--tags");
688686
if (argc >= 2)
689687
die(_("--mirror can't be combined with refspecs"));
690688
}
691-
if ((flags & TRANSPORT_PUSH_ALL) && (flags & TRANSPORT_PUSH_MIRROR))
692-
die(_("options '%s' and '%s' cannot be used together"), "--all", "--mirror");
693689

694690
if (!is_empty_cas(&cas) && (flags & TRANSPORT_PUSH_FORCE_IF_INCLUDES))
695691
cas.use_force_if_includes = 1;

builtin/repack.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,19 +1203,13 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
12031203
if (delete_redundant && repository_format_precious_objects)
12041204
die(_("cannot delete packs in a precious-objects repo"));
12051205

1206-
if (keep_unreachable &&
1207-
(unpack_unreachable || (pack_everything & LOOSEN_UNREACHABLE)))
1208-
die(_("options '%s' and '%s' cannot be used together"), "--keep-unreachable", "-A");
1206+
die_for_incompatible_opt3(unpack_unreachable || (pack_everything & LOOSEN_UNREACHABLE), "-A",
1207+
keep_unreachable, "-k/--keep-unreachable",
1208+
pack_everything & PACK_CRUFT, "--cruft");
12091209

1210-
if (pack_everything & PACK_CRUFT) {
1210+
if (pack_everything & PACK_CRUFT)
12111211
pack_everything |= ALL_INTO_ONE;
12121212

1213-
if (unpack_unreachable || (pack_everything & LOOSEN_UNREACHABLE))
1214-
die(_("options '%s' and '%s' cannot be used together"), "--cruft", "-A");
1215-
if (keep_unreachable)
1216-
die(_("options '%s' and '%s' cannot be used together"), "--cruft", "-k");
1217-
}
1218-
12191213
if (write_bitmaps < 0) {
12201214
if (!write_midx &&
12211215
(!(pack_everything & ALL_INTO_ONE) || !is_bare_repository()))

builtin/rev-parse.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -893,13 +893,15 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
893893
}
894894
if (opt_with_value(arg, "--branches", &arg)) {
895895
if (ref_excludes.hidden_refs_configured)
896-
return error(_("--exclude-hidden cannot be used together with --branches"));
896+
return error(_("options '%s' and '%s' cannot be used together"),
897+
"--exclude-hidden", "--branches");
897898
handle_ref_opt(arg, "refs/heads/");
898899
continue;
899900
}
900901
if (opt_with_value(arg, "--tags", &arg)) {
901902
if (ref_excludes.hidden_refs_configured)
902-
return error(_("--exclude-hidden cannot be used together with --tags"));
903+
return error(_("options '%s' and '%s' cannot be used together"),
904+
"--exclude-hidden", "--tags");
903905
handle_ref_opt(arg, "refs/tags/");
904906
continue;
905907
}
@@ -909,7 +911,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
909911
}
910912
if (opt_with_value(arg, "--remotes", &arg)) {
911913
if (ref_excludes.hidden_refs_configured)
912-
return error(_("--exclude-hidden cannot be used together with --remotes"));
914+
return error(_("options '%s' and '%s' cannot be used together"),
915+
"--exclude-hidden", "--remotes");
913916
handle_ref_opt(arg, "refs/remotes/");
914917
continue;
915918
}

builtin/worktree.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -730,11 +730,11 @@ static int dwim_orphan(const struct add_opts *opts, int opt_track, int remote)
730730
}
731731

732732
if (opt_track) {
733-
die(_("'%s' and '%s' cannot be used together"), "--orphan",
734-
"--track");
733+
die(_("options '%s' and '%s' cannot be used together"),
734+
"--orphan", "--track");
735735
} else if (!opts->checkout) {
736-
die(_("'%s' and '%s' cannot be used together"), "--orphan",
737-
"--no-checkout");
736+
die(_("options '%s' and '%s' cannot be used together"),
737+
"--orphan", "--no-checkout");
738738
}
739739
return 1;
740740
}
@@ -806,16 +806,17 @@ static int add(int ac, const char **av, const char *prefix)
806806
if (!!opts.detach + !!new_branch + !!new_branch_force > 1)
807807
die(_("options '%s', '%s', and '%s' cannot be used together"), "-b", "-B", "--detach");
808808
if (opts.detach && opts.orphan)
809-
die(_("options '%s', and '%s' cannot be used together"),
809+
die(_("options '%s' and '%s' cannot be used together"),
810810
"--orphan", "--detach");
811811
if (opts.orphan && opt_track)
812-
die(_("'%s' and '%s' cannot be used together"), "--orphan", "--track");
812+
die(_("options '%s' and '%s' cannot be used together"),
813+
"--orphan", "--track");
813814
if (opts.orphan && !opts.checkout)
814-
die(_("'%s' and '%s' cannot be used together"), "--orphan",
815-
"--no-checkout");
815+
die(_("options '%s' and '%s' cannot be used together"),
816+
"--orphan", "--no-checkout");
816817
if (opts.orphan && ac == 2)
817-
die(_("'%s' and '%s' cannot be used together"), "--orphan",
818-
_("<commit-ish>"));
818+
die(_("option '%s' and commit-ish cannot be used together"),
819+
"--orphan");
819820
if (lock_reason && !keep_locked)
820821
die(_("the option '%s' requires '%s'"), "--reason", "--lock");
821822
if (lock_reason)

revision.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2728,7 +2728,8 @@ static int handle_revision_pseudo_opt(struct rev_info *revs,
27282728
clear_ref_exclusions(&revs->ref_excludes);
27292729
} else if (!strcmp(arg, "--branches")) {
27302730
if (revs->ref_excludes.hidden_refs_configured)
2731-
return error(_("--exclude-hidden cannot be used together with --branches"));
2731+
return error(_("options '%s' and '%s' cannot be used together"),
2732+
"--exclude-hidden", "--branches");
27322733
handle_refs(refs, revs, *flags, refs_for_each_branch_ref);
27332734
clear_ref_exclusions(&revs->ref_excludes);
27342735
} else if (!strcmp(arg, "--bisect")) {
@@ -2739,12 +2740,14 @@ static int handle_revision_pseudo_opt(struct rev_info *revs,
27392740
revs->bisect = 1;
27402741
} else if (!strcmp(arg, "--tags")) {
27412742
if (revs->ref_excludes.hidden_refs_configured)
2742-
return error(_("--exclude-hidden cannot be used together with --tags"));
2743+
return error(_("options '%s' and '%s' cannot be used together"),
2744+
"--exclude-hidden", "--tags");
27432745
handle_refs(refs, revs, *flags, refs_for_each_tag_ref);
27442746
clear_ref_exclusions(&revs->ref_excludes);
27452747
} else if (!strcmp(arg, "--remotes")) {
27462748
if (revs->ref_excludes.hidden_refs_configured)
2747-
return error(_("--exclude-hidden cannot be used together with --remotes"));
2749+
return error(_("options '%s' and '%s' cannot be used together"),
2750+
"--exclude-hidden", "--remotes");
27482751
handle_refs(refs, revs, *flags, refs_for_each_remote_ref);
27492752
clear_ref_exclusions(&revs->ref_excludes);
27502753
} else if ((argcount = parse_long_opt("glob", argv, &optarg))) {
@@ -2762,21 +2765,24 @@ static int handle_revision_pseudo_opt(struct rev_info *revs,
27622765
} else if (skip_prefix(arg, "--branches=", &optarg)) {
27632766
struct all_refs_cb cb;
27642767
if (revs->ref_excludes.hidden_refs_configured)
2765-
return error(_("--exclude-hidden cannot be used together with --branches"));
2768+
return error(_("options '%s' and '%s' cannot be used together"),
2769+
"--exclude-hidden", "--branches");
27662770
init_all_refs_cb(&cb, revs, *flags);
27672771
for_each_glob_ref_in(handle_one_ref, optarg, "refs/heads/", &cb);
27682772
clear_ref_exclusions(&revs->ref_excludes);
27692773
} else if (skip_prefix(arg, "--tags=", &optarg)) {
27702774
struct all_refs_cb cb;
27712775
if (revs->ref_excludes.hidden_refs_configured)
2772-
return error(_("--exclude-hidden cannot be used together with --tags"));
2776+
return error(_("options '%s' and '%s' cannot be used together"),
2777+
"--exclude-hidden", "--tags");
27732778
init_all_refs_cb(&cb, revs, *flags);
27742779
for_each_glob_ref_in(handle_one_ref, optarg, "refs/tags/", &cb);
27752780
clear_ref_exclusions(&revs->ref_excludes);
27762781
} else if (skip_prefix(arg, "--remotes=", &optarg)) {
27772782
struct all_refs_cb cb;
27782783
if (revs->ref_excludes.hidden_refs_configured)
2779-
return error(_("--exclude-hidden cannot be used together with --remotes"));
2784+
return error(_("options '%s' and '%s' cannot be used together"),
2785+
"--exclude-hidden", "--remotes");
27802786
init_all_refs_cb(&cb, revs, *flags);
27812787
for_each_glob_ref_in(handle_one_ref, optarg, "refs/remotes/", &cb);
27822788
clear_ref_exclusions(&revs->ref_excludes);
@@ -3055,8 +3061,6 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
30553061
revs->grep_filter.ignore_locale = 1;
30563062
compile_grep_patterns(&revs->grep_filter);
30573063

3058-
if (revs->reverse && revs->reflog_info)
3059-
die(_("options '%s' and '%s' cannot be used together"), "--reverse", "--walk-reflogs");
30603064
if (revs->reflog_info && revs->limited)
30613065
die("cannot combine --walk-reflogs with history-limiting options");
30623066
if (revs->rewrite_parents && revs->children.name)
@@ -3067,11 +3071,10 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
30673071
/*
30683072
* Limitations on the graph functionality
30693073
*/
3070-
if (revs->reverse && revs->graph)
3071-
die(_("options '%s' and '%s' cannot be used together"), "--reverse", "--graph");
3074+
die_for_incompatible_opt3(!!revs->graph, "--graph",
3075+
!!revs->reverse, "--reverse",
3076+
!!revs->reflog_info, "--walk-reflogs");
30723077

3073-
if (revs->reflog_info && revs->graph)
3074-
die(_("options '%s' and '%s' cannot be used together"), "--walk-reflogs", "--graph");
30753078
if (revs->no_walk && revs->graph)
30763079
die(_("options '%s' and '%s' cannot be used together"), "--no-walk", "--graph");
30773080
if (!revs->reflog_info && revs->grep_filter.use_reflog_filter)

t/t2400-worktree-add.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ test_dwim_orphan () {
711711
local fetch_error_text="fatal: No local or remote refs exist despite at least one remote" &&
712712
local orphan_hint="hint: If you meant to create a worktree containing a new orphan branch" &&
713713
local invalid_ref_regex="^fatal: invalid reference: " &&
714-
local bad_combo_regex="^fatal: '[-a-z]*' and '[-a-z]*' cannot be used together" &&
714+
local bad_combo_regex="^fatal: options '[-a-z]*' and '[-a-z]*' cannot be used together" &&
715715

716716
local git_ns="repo" &&
717717
local dashc_args="-C $git_ns" &&

t/t6018-rev-list-glob.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,13 @@ do
214214
for pseudoopt in branches tags remotes
215215
do
216216
test_expect_success "rev-parse --exclude-hidden=$section fails with --$pseudoopt" '
217-
echo "error: --exclude-hidden cannot be used together with --$pseudoopt" >expected &&
218217
test_must_fail git rev-parse --exclude-hidden=$section --$pseudoopt 2>err &&
219-
test_cmp expected err
218+
test_grep "error: options .--exclude-hidden. and .--$pseudoopt. cannot be used together" err
220219
'
221220

222221
test_expect_success "rev-parse --exclude-hidden=$section fails with --$pseudoopt=pattern" '
223-
echo "error: --exclude-hidden cannot be used together with --$pseudoopt" >expected &&
224222
test_must_fail git rev-parse --exclude-hidden=$section --$pseudoopt=pattern 2>err &&
225-
test_cmp expected err
223+
test_grep "error: options .--exclude-hidden. and .--$pseudoopt. cannot be used together" err
226224
'
227225
done
228226
done

t/t6021-rev-list-exclude-hidden.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,12 @@ do
151151
do
152152
test_expect_success "$section: fails with --$pseudoopt" '
153153
test_must_fail git rev-list --exclude-hidden=$section --$pseudoopt 2>err &&
154-
test_grep "error: --exclude-hidden cannot be used together with --$pseudoopt" err
154+
test_grep "error: options .--exclude-hidden. and .--$pseudoopt. cannot be used together" err
155155
'
156156

157157
test_expect_success "$section: fails with --$pseudoopt=pattern" '
158158
test_must_fail git rev-list --exclude-hidden=$section --$pseudoopt=pattern 2>err &&
159-
test_grep "error: --exclude-hidden cannot be used together with --$pseudoopt" err
159+
test_grep "error: options .--exclude-hidden. and .--$pseudoopt. cannot be used together" err
160160
'
161161
done
162162
done

0 commit comments

Comments
 (0)