@matheusbsbs / matheus-bagliano / commits / 01bbbbd9da
Fork 0

fetch: allow adding a filter after initial clone

Retroactively adding a filter can be useful for existing shallow clones as they allow users to see earlier change histories without downloading all git objects in a regular --unshallow fetch. Without this patch, users can make a clone partial by editing the repository configuration to convert the remote into a promisor, like:   git config core.repositoryFormatVersion 1   git config extensions.partialClone origin   git fetch --unshallow --filter=blob:none origin Since the hard part of making this work is already in place and such edits can be error-prone, teach Git to perform the required configuration change automatically instead. Note that this change does not modify the existing git behavior which recognizes setting extensions.partialClone without changing repositoryFormatVersion. Signed-off-by: Xin Li <delphij@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Xin Li committed Jun 5, 2020 at 02:10 UTC 01bbbbd9daaa277a95ae46e5a32f6fba026610ac
5 files changed +12 -6
builtin/fetch.c
-3
@@ -1790,9 +1790,6 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
1790 if (depth || deepen_since || deepen_not.nr)
1791 deepen = 1;
1792
1793 - if (filter_options.choice && !has_promisor_remote())
1794 - die("--filter can only be used when extensions.partialClone is set");
1795 -
1793 if (all) {
1794 if (argc == 1)
1795 die(_("fetch --all does not take a repository argument"));
t/t0410-partial-clone.sh
+12
@@ -30,6 +30,18 @@ test_expect_success 'extensions.partialclone without filter' '
30 git -C client fetch origin
31 '
32
33 +test_expect_success 'convert shallow clone to partial clone' '
34 + rm -fr server client &&
35 + test_create_repo server &&
36 + test_commit -C server my_commit 1 &&
37 + test_commit -C server my_commit2 1 &&
38 + git clone --depth=1 "file://$(pwd)/server" client &&
39 + git -C client fetch --unshallow --filter="blob:none" &&
40 + test_cmp_config -C client true remote.origin.promisor &&
41 + test_cmp_config -C client blob:none remote.origin.partialclonefilter &&
42 + test_cmp_config -C client 1 core.repositoryformatversion
43 +'
44 +
45 test_expect_success 'missing reflog object, but promised by a commit, passes fsck' '
46 rm -rf repo &&
47 test_create_repo repo &&
t/t1090-sparse-checkout-scope.sh
-1
@@ -63,7 +63,6 @@ test_expect_success 'in partial clone, sparse checkout only fetches needed blobs
63 git -C server commit -m message &&
64
65 test_config -C client core.sparsecheckout 1 &&
66 - test_config -C client extensions.partialclone origin &&
66 echo "!/*" >client/.git/info/sparse-checkout &&
67 echo "/a" >>client/.git/info/sparse-checkout &&
68 git -C client fetch --filter=blob:none origin &&
t/t5500-fetch-pack.sh
-1
@@ -999,7 +999,6 @@ fetch_filter_blob_limit_zero () {
999 test_config -C "$SERVER" uploadpack.allowfilter 1 &&
1000
1001 git clone "$URL" client &&
1002 - test_config -C client extensions.partialclone origin &&
1002
1003 test_commit -C "$SERVER" two &&
1004
t/t5702-protocol-v2.sh
-1
@@ -348,7 +348,6 @@ test_expect_success 'partial fetch' '
348 rm -rf client "$(pwd)/trace" &&
349 git init client &&
350 SERVER="file://$(pwd)/server" &&
351 - test_config -C client extensions.partialClone "$SERVER" &&
351
352 GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
353 fetch --filter=blob:none "$SERVER" master:refs/heads/other &&