Skip to content

Commit 9562f19

Browse files
committed
Merge branch 'jc/transport-parseopt-fix'
Command line parser fixes. * jc/transport-parseopt-fix: fetch: reject --no-ipv[46] parse-options: introduce OPT_IPVERSION()
2 parents 7fb1483 + a2dad48 commit 9562f19

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

builtin/clone.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,7 @@ static struct option builtin_clone_options[] = {
161161
N_("set config inside the new repository")),
162162
OPT_STRING_LIST(0, "server-option", &server_options,
163163
N_("server-specific"), N_("option to transmit")),
164-
OPT_SET_INT('4', "ipv4", &family, N_("use IPv4 addresses only"),
165-
TRANSPORT_FAMILY_IPV4),
166-
OPT_SET_INT('6', "ipv6", &family, N_("use IPv6 addresses only"),
167-
TRANSPORT_FAMILY_IPV6),
164+
OPT_IPVERSION(&family),
168165
OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options),
169166
OPT_BOOL(0, "also-filter-submodules", &option_filter_submodules,
170167
N_("apply partial clone filters to submodules")),

builtin/fetch.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2207,10 +2207,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
22072207
OPT_CALLBACK_F(0, "refmap", NULL, N_("refmap"),
22082208
N_("specify fetch refmap"), PARSE_OPT_NONEG, parse_refmap_arg),
22092209
OPT_STRING_LIST('o', "server-option", &server_options, N_("server-specific"), N_("option to transmit")),
2210-
OPT_SET_INT('4', "ipv4", &family, N_("use IPv4 addresses only"),
2211-
TRANSPORT_FAMILY_IPV4),
2212-
OPT_SET_INT('6', "ipv6", &family, N_("use IPv6 addresses only"),
2213-
TRANSPORT_FAMILY_IPV6),
2210+
OPT_IPVERSION(&family),
22142211
OPT_STRING_LIST(0, "negotiation-tip", &negotiation_tip, N_("revision"),
22152212
N_("report that we have only objects reachable from this object")),
22162213
OPT_BOOL(0, "negotiate-only", &negotiate_only,

builtin/push.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -627,10 +627,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)
627627
PARSE_OPT_OPTARG, option_parse_push_signed),
628628
OPT_BIT(0, "atomic", &flags, N_("request atomic transaction on remote side"), TRANSPORT_PUSH_ATOMIC),
629629
OPT_STRING_LIST('o', "push-option", &push_options_cmdline, N_("server-specific"), N_("option to transmit")),
630-
OPT_SET_INT('4', "ipv4", &family, N_("use IPv4 addresses only"),
631-
TRANSPORT_FAMILY_IPV4),
632-
OPT_SET_INT('6', "ipv6", &family, N_("use IPv6 addresses only"),
633-
TRANSPORT_FAMILY_IPV6),
630+
OPT_IPVERSION(&family),
634631
OPT_END()
635632
};
636633

parse-options.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,4 +581,10 @@ int parse_opt_tracking_mode(const struct option *, const char *, int);
581581
#define OPT_PATHSPEC_FILE_NUL(v) OPT_BOOL(0, "pathspec-file-nul", v, N_("with --pathspec-from-file, pathspec elements are separated with NUL character"))
582582
#define OPT_AUTOSTASH(v) OPT_BOOL(0, "autostash", v, N_("automatically stash/stash pop before and after"))
583583

584+
#define OPT_IPVERSION(v) \
585+
OPT_SET_INT_F('4', "ipv4", (v), N_("use IPv4 addresses only"), \
586+
TRANSPORT_FAMILY_IPV4, PARSE_OPT_NONEG), \
587+
OPT_SET_INT_F('6', "ipv6", (v), N_("use IPv6 addresses only"), \
588+
TRANSPORT_FAMILY_IPV6, PARSE_OPT_NONEG)
589+
584590
#endif

t/t5516-fetch-push.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,17 @@ test_expect_success setup '
120120
121121
'
122122

123+
for cmd in push fetch
124+
do
125+
for opt in ipv4 ipv6
126+
do
127+
test_expect_success "reject 'git $cmd --no-$opt'" '
128+
test_must_fail git $cmd --no-$opt 2>err &&
129+
grep "unknown option .no-$opt" err
130+
'
131+
done
132+
done
133+
123134
test_expect_success 'fetch without wildcard' '
124135
mk_empty testrepo &&
125136
(

0 commit comments

Comments
 (0)