@@ -1275,6 +1275,56 @@ static int fetch_multiple(struct string_list *list)
1275
1275
return result ;
1276
1276
}
1277
1277
1278
+ /*
1279
+ * Fetching from the promisor remote should use the given filter-spec
1280
+ * or inherit the default filter-spec from the config.
1281
+ */
1282
+ static inline void fetch_one_setup_partial (struct remote * remote )
1283
+ {
1284
+ /*
1285
+ * Explicit --no-filter argument overrides everything, regardless
1286
+ * of any prior partial clones and fetches.
1287
+ */
1288
+ if (filter_options .no_filter )
1289
+ return ;
1290
+
1291
+ /*
1292
+ * If no prior partial clone/fetch and the current fetch DID NOT
1293
+ * request a partial-fetch, do a normal fetch.
1294
+ */
1295
+ if (!repository_format_partial_clone && !filter_options .choice )
1296
+ return ;
1297
+
1298
+ /*
1299
+ * If this is the FIRST partial-fetch request, we enable partial
1300
+ * on this repo and remember the given filter-spec as the default
1301
+ * for subsequent fetches to this remote.
1302
+ */
1303
+ if (!repository_format_partial_clone && filter_options .choice ) {
1304
+ partial_clone_register (remote -> name , & filter_options );
1305
+ return ;
1306
+ }
1307
+
1308
+ /*
1309
+ * We are currently limited to only ONE promisor remote and only
1310
+ * allow partial-fetches from the promisor remote.
1311
+ */
1312
+ if (strcmp (remote -> name , repository_format_partial_clone )) {
1313
+ if (filter_options .choice )
1314
+ die (_ ("--filter can only be used with the remote configured in core.partialClone" ));
1315
+ return ;
1316
+ }
1317
+
1318
+ /*
1319
+ * Do a partial-fetch from the promisor remote using either the
1320
+ * explicitly given filter-spec or inherit the filter-spec from
1321
+ * the config.
1322
+ */
1323
+ if (!filter_options .choice )
1324
+ partial_clone_get_default_filter_spec (& filter_options );
1325
+ return ;
1326
+ }
1327
+
1278
1328
static int fetch_one (struct remote * remote , int argc , const char * * argv )
1279
1329
{
1280
1330
static const char * * refs = NULL ;
@@ -1404,13 +1454,13 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
1404
1454
}
1405
1455
1406
1456
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" ));
1457
+ if (filter_options .choice || repository_format_partial_clone )
1458
+ fetch_one_setup_partial (remote );
1410
1459
result = fetch_one (remote , argc , argv );
1411
1460
} else {
1412
1461
if (filter_options .choice )
1413
1462
die (_ ("--filter can only be used with the remote configured in core.partialClone" ));
1463
+ /* TODO should this also die if we have a previous partial-clone? */
1414
1464
result = fetch_multiple (& list );
1415
1465
}
1416
1466
0 commit comments