|
18 | 18 | #include "argv-array.h" |
19 | 19 | #include "utf8.h" |
20 | 20 | #include "packfile.h" |
| 21 | +#include "list-objects-filter-options.h" |
21 | 22 |
|
22 | 23 | static const char * const builtin_fetch_usage[] = { |
23 | 24 | N_("git fetch [<options>] [<repository> [<refspec>...]]"), |
@@ -55,6 +56,7 @@ static int recurse_submodules_default = RECURSE_SUBMODULES_ON_DEMAND; |
55 | 56 | static int shown_url = 0; |
56 | 57 | static int refmap_alloc, refmap_nr; |
57 | 58 | static const char **refmap_array; |
| 59 | +static struct list_objects_filter_options filter_options; |
58 | 60 |
|
59 | 61 | static int git_fetch_config(const char *k, const char *v, void *cb) |
60 | 62 | { |
@@ -160,6 +162,7 @@ static struct option builtin_fetch_options[] = { |
160 | 162 | TRANSPORT_FAMILY_IPV4), |
161 | 163 | OPT_SET_INT('6', "ipv6", &family, N_("use IPv6 addresses only"), |
162 | 164 | TRANSPORT_FAMILY_IPV6), |
| 165 | + OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options), |
163 | 166 | OPT_END() |
164 | 167 | }; |
165 | 168 |
|
@@ -1044,6 +1047,11 @@ static struct transport *prepare_transport(struct remote *remote, int deepen) |
1044 | 1047 | set_option(transport, TRANS_OPT_DEEPEN_RELATIVE, "yes"); |
1045 | 1048 | if (update_shallow) |
1046 | 1049 | set_option(transport, TRANS_OPT_UPDATE_SHALLOW, "yes"); |
| 1050 | + if (filter_options.choice) { |
| 1051 | + set_option(transport, TRANS_OPT_LIST_OBJECTS_FILTER, |
| 1052 | + filter_options.filter_spec); |
| 1053 | + set_option(transport, TRANS_OPT_FROM_PROMISOR, "1"); |
| 1054 | + } |
1047 | 1055 | return transport; |
1048 | 1056 | } |
1049 | 1057 |
|
@@ -1328,6 +1336,8 @@ int cmd_fetch(int argc, const char **argv, const char *prefix) |
1328 | 1336 |
|
1329 | 1337 | packet_trace_identity("fetch"); |
1330 | 1338 |
|
| 1339 | + fetch_if_missing = 0; |
| 1340 | + |
1331 | 1341 | /* Record the command line for the reflog */ |
1332 | 1342 | strbuf_addstr(&default_rla, "fetch"); |
1333 | 1343 | for (i = 1; i < argc; i++) |
@@ -1361,6 +1371,9 @@ int cmd_fetch(int argc, const char **argv, const char *prefix) |
1361 | 1371 | if (depth || deepen_since || deepen_not.nr) |
1362 | 1372 | deepen = 1; |
1363 | 1373 |
|
| 1374 | + if (filter_options.choice && !repository_format_partial_clone) |
| 1375 | + die("--filter can only be used when extensions.partialClone is set"); |
| 1376 | + |
1364 | 1377 | if (all) { |
1365 | 1378 | if (argc == 1) |
1366 | 1379 | die(_("fetch --all does not take a repository argument")); |
@@ -1390,10 +1403,16 @@ int cmd_fetch(int argc, const char **argv, const char *prefix) |
1390 | 1403 | } |
1391 | 1404 | } |
1392 | 1405 |
|
1393 | | - if (remote) |
| 1406 | + if (remote) { |
| 1407 | + if (filter_options.choice && |
| 1408 | + strcmp(remote->name, repository_format_partial_clone)) |
| 1409 | + die(_("--filter can only be used with the remote configured in core.partialClone")); |
1394 | 1410 | result = fetch_one(remote, argc, argv); |
1395 | | - else |
| 1411 | + } else { |
| 1412 | + if (filter_options.choice) |
| 1413 | + die(_("--filter can only be used with the remote configured in core.partialClone")); |
1396 | 1414 | result = fetch_multiple(&list); |
| 1415 | + } |
1397 | 1416 |
|
1398 | 1417 | if (!result && (recurse_submodules != RECURSE_SUBMODULES_OFF)) { |
1399 | 1418 | struct argv_array options = ARGV_ARRAY_INIT; |
|
0 commit comments