revision, rev-parse: factorize incompatibility messages about - -exclude-hidden
Use the standard parameterized message for reporting incompatible options to report options that are not accepted in combination with --exclude-hidden. This reduces the number of strings to translate and makes the UI a bit more consistent. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Dec 6, 2023 at 12:51 UTC
81fb70f55e93ca0b5f013284e15aec0ee9f79824
4 files changed
+22
-15
builtin/rev-parse.c
+6
-3
@@ -893,13 +893,15 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
893
}
894
if (opt_with_value(arg, "--branches", &arg)) {
895
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");
898
handle_ref_opt(arg, "refs/heads/");
899
continue;
900
}
901
if (opt_with_value(arg, "--tags", &arg)) {
902
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");
905
handle_ref_opt(arg, "refs/tags/");
906
continue;
907
}
@@ -909,7 +911,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
911
}
912
if (opt_with_value(arg, "--remotes", &arg)) {
913
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");
916
handle_ref_opt(arg, "refs/remotes/");
917
continue;
918
}
revision.c
+12
-6
@@ -2709,7 +2709,8 @@ static int handle_revision_pseudo_opt(struct rev_info *revs,
2709
clear_ref_exclusions(&revs->ref_excludes);
2710
} else if (!strcmp(arg, "--branches")) {
2711
if (revs->ref_excludes.hidden_refs_configured)
2712
- return error(_("--exclude-hidden cannot be used together with --branches"));
2712
+ return error(_("options '%s' and '%s' cannot be used together"),
2713
+ "--exclude-hidden", "--branches");
2714
handle_refs(refs, revs, *flags, refs_for_each_branch_ref);
2715
clear_ref_exclusions(&revs->ref_excludes);
2716
} else if (!strcmp(arg, "--bisect")) {
@@ -2720,12 +2721,14 @@ static int handle_revision_pseudo_opt(struct rev_info *revs,
2721
revs->bisect = 1;
2722
} else if (!strcmp(arg, "--tags")) {
2723
if (revs->ref_excludes.hidden_refs_configured)
2723
- return error(_("--exclude-hidden cannot be used together with --tags"));
2724
+ return error(_("options '%s' and '%s' cannot be used together"),
2725
+ "--exclude-hidden", "--tags");
2726
handle_refs(refs, revs, *flags, refs_for_each_tag_ref);
2727
clear_ref_exclusions(&revs->ref_excludes);
2728
} else if (!strcmp(arg, "--remotes")) {
2729
if (revs->ref_excludes.hidden_refs_configured)
2728
- return error(_("--exclude-hidden cannot be used together with --remotes"));
2730
+ return error(_("options '%s' and '%s' cannot be used together"),
2731
+ "--exclude-hidden", "--remotes");
2732
handle_refs(refs, revs, *flags, refs_for_each_remote_ref);
2733
clear_ref_exclusions(&revs->ref_excludes);
2734
} else if ((argcount = parse_long_opt("glob", argv, &optarg))) {
@@ -2743,21 +2746,24 @@ static int handle_revision_pseudo_opt(struct rev_info *revs,
2746
} else if (skip_prefix(arg, "--branches=", &optarg)) {
2747
struct all_refs_cb cb;
2748
if (revs->ref_excludes.hidden_refs_configured)
2746
- return error(_("--exclude-hidden cannot be used together with --branches"));
2749
+ return error(_("options '%s' and '%s' cannot be used together"),
2750
+ "--exclude-hidden", "--branches");
2751
init_all_refs_cb(&cb, revs, *flags);
2752
for_each_glob_ref_in(handle_one_ref, optarg, "refs/heads/", &cb);
2753
clear_ref_exclusions(&revs->ref_excludes);
2754
} else if (skip_prefix(arg, "--tags=", &optarg)) {
2755
struct all_refs_cb cb;
2756
if (revs->ref_excludes.hidden_refs_configured)
2753
- return error(_("--exclude-hidden cannot be used together with --tags"));
2757
+ return error(_("options '%s' and '%s' cannot be used together"),
2758
+ "--exclude-hidden", "--tags");
2759
init_all_refs_cb(&cb, revs, *flags);
2760
for_each_glob_ref_in(handle_one_ref, optarg, "refs/tags/", &cb);
2761
clear_ref_exclusions(&revs->ref_excludes);
2762
} else if (skip_prefix(arg, "--remotes=", &optarg)) {
2763
struct all_refs_cb cb;
2764
if (revs->ref_excludes.hidden_refs_configured)
2760
- return error(_("--exclude-hidden cannot be used together with --remotes"));
2765
+ return error(_("options '%s' and '%s' cannot be used together"),
2766
+ "--exclude-hidden", "--remotes");
2767
init_all_refs_cb(&cb, revs, *flags);
2768
for_each_glob_ref_in(handle_one_ref, optarg, "refs/remotes/", &cb);
2769
clear_ref_exclusions(&revs->ref_excludes);
t/t6018-rev-list-glob.sh
+2
-4
@@ -214,15 +214,13 @@ do
214
for pseudoopt in branches tags remotes
215
do
216
test_expect_success "rev-parse --exclude-hidden=$section fails with --$pseudoopt" '
217
- echo "error: --exclude-hidden cannot be used together with --$pseudoopt" >expected &&
217
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
219
'
220
221
test_expect_success "rev-parse --exclude-hidden=$section fails with --$pseudoopt=pattern" '
223
- echo "error: --exclude-hidden cannot be used together with --$pseudoopt" >expected &&
222
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
224
'
225
done
226
done
t/t6021-rev-list-exclude-hidden.sh
+2
-2
@@ -151,12 +151,12 @@ do
151
do
152
test_expect_success "$section: fails with --$pseudoopt" '
153
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
155
'
156
157
test_expect_success "$section: fails with --$pseudoopt=pattern" '
158
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
160
'
161
done
162
done