3 test_description='git partial clone'
7 # create a normal "src" repo where we can later create new commits.
8 # expect_1.oids will contain a list of the OIDs of all blobs.
9 test_expect_success 'setup normal src repo' '
10 echo "{print \$1}" >print_1.awk &&
11 echo "{print \$2}" >print_2.awk &&
16 echo "This is file: $n" > src/file.$n.txt
17 git -C src add file.$n.txt
18 git -C src commit -m "file $n"
19 git -C src ls-files -s file.$n.txt >>temp
21 awk -f print_2.awk <temp | sort >expect_1.oids &&
22 test_line_count = 4 expect_1.oids
25 # bare clone "src" giving "srv.bare" for use as our server.
26 test_expect_success 'setup bare clone for server' '
27 git clone --bare "file://$(pwd)/src" srv.bare &&
28 git -C srv.bare config --local uploadpack.allowfilter 1 &&
29 git -C srv.bare config --local uploadpack.allowanysha1inwant 1
32 # do basic partial clone from "srv.bare"
33 # confirm we are missing all of the known blobs.
34 # confirm partial clone was registered in the local config.
35 test_expect_success 'do partial clone 1' '
36 git clone --no-checkout --filter=blob:none "file://$(pwd)/srv.bare" pc1 &&
38 git -C pc1 rev-list --quiet --objects --missing=print HEAD >revs &&
39 awk -f print_1.awk revs |
41 sort >observed.oids &&
43 test_cmp expect_1.oids observed.oids &&
44 test "$(git -C pc1 config --local core.repositoryformatversion)" = "1" &&
45 test "$(git -C pc1 config --local extensions.partialclone)" = "origin" &&
46 test "$(git -C pc1 config --local core.partialclonefilter)" = "blob:none"
49 # checkout master to force dynamic object fetch of blobs at HEAD.
50 test_expect_success 'verify checkout with dynamic object fetch' '
51 git -C pc1 rev-list --quiet --objects --missing=print HEAD >observed &&
52 test_line_count = 4 observed &&
53 git -C pc1 checkout master &&
54 git -C pc1 rev-list --quiet --objects --missing=print HEAD >observed &&
55 test_line_count = 0 observed
58 # create new commits in "src" repo to establish a blame history on file.1.txt
59 # and push to "srv.bare".
60 test_expect_success 'push new commits to server' '
61 git -C src remote add srv "file://$(pwd)/srv.bare" &&
64 echo "Mod file.1.txt $x" >>src/file.1.txt
65 git -C src add file.1.txt
66 git -C src commit -m "mod $x"
68 git -C src blame master -- file.1.txt >expect.blame &&
69 git -C src push -u srv master
72 # (partial) fetch in the partial clone repo from the promisor remote.
73 # verify that fetch inherited the filter-spec from the config and DOES NOT
75 test_expect_success 'partial fetch inherits filter settings' '
76 git -C pc1 fetch origin &&
77 git -C pc1 rev-list --quiet --objects --missing=print \
78 master..origin/master >observed &&
79 test_line_count = 5 observed
82 # force dynamic object fetch using diff.
83 # we should only get 1 new blob (for the file in origin/master).
84 test_expect_success 'verify diff causes dynamic object fetch' '
85 git -C pc1 diff master..origin/master -- file.1.txt &&
86 git -C pc1 rev-list --quiet --objects --missing=print \
87 master..origin/master >observed &&
88 test_line_count = 4 observed
91 # force full dynamic object fetch of the file's history using blame.
92 # we should get the intermediate blobs for the file.
93 test_expect_success 'verify blame causes dynamic object fetch' '
94 git -C pc1 blame origin/master -- file.1.txt >observed.blame &&
95 test_cmp expect.blame observed.blame &&
96 git -C pc1 rev-list --quiet --objects --missing=print \
97 master..origin/master >observed &&
98 test_line_count = 0 observed
101 # create new commits in "src" repo to establish a history on file.2.txt
102 # and push to "srv.bare".
103 test_expect_success 'push new commits to server for file.2.txt' '
106 echo "Mod file.2.txt $x" >>src/file.2.txt
107 git -C src add file.2.txt
108 git -C src commit -m "mod $x"
110 git -C src push -u srv master
113 # Do FULL fetch by disabling inherited filter-spec using --no-filter.
114 # Verify we have all the new blobs.
115 test_expect_success 'override inherited filter-spec using --no-filter' '
116 git -C pc1 fetch --no-filter origin &&
117 git -C pc1 rev-list --quiet --objects --missing=print \
118 master..origin/master >observed &&
119 test_line_count = 0 observed
122 # create new commits in "src" repo to establish a history on file.3.txt
123 # and push to "srv.bare".
124 test_expect_success 'push new commits to server for file.3.txt' '
127 echo "Mod file.3.txt $x" >>src/file.3.txt
128 git -C src add file.3.txt
129 git -C src commit -m "mod $x"
131 git -C src push -u srv master
134 # Do a partial fetch and then try to manually fetch the missing objects.
135 # This can be used as the basis of a pre-command hook to bulk fetch objects
136 # perhaps combined with a command in dry-run mode.
137 test_expect_success 'manual prefetch of missing objects' '
138 git -C pc1 fetch --filter=blob:none origin &&
140 git -C pc1 rev-list --quiet --objects --missing=print \
141 master..origin/master >revs &&
142 awk -f print_1.awk revs |
144 sort >observed.oids &&
146 test_line_count = 6 observed.oids &&
147 git -C pc1 fetch-pack --stdin "file://$(pwd)/srv.bare" <observed.oids &&
149 git -C pc1 rev-list --quiet --objects --missing=print \
150 master..origin/master >revs &&
151 awk -f print_1.awk revs |
153 sort >observed.oids &&
155 test_line_count = 0 observed.oids
158 test_expect_success 'partial clone with transfer.fsckobjects=1 uses index-pack --fsck-objects' '
160 test_commit -C src x &&
161 test_config -C src uploadpack.allowfilter 1 &&
162 test_config -C src uploadpack.allowanysha1inwant 1 &&
164 GIT_TRACE="$(pwd)/trace" git -c transfer.fsckobjects=1 \
165 clone --filter="blob:none" "file://$(pwd)/src" dst &&
166 grep "git index-pack.*--fsck-objects" trace
169 test_expect_success 'partial clone fetches blobs pointed to by refs even if normally filtered out' '
172 test_commit -C src x &&
173 test_config -C src uploadpack.allowfilter 1 &&
174 test_config -C src uploadpack.allowanysha1inwant 1 &&
176 # Create a tag pointing to a blob.
177 BLOB=$(echo blob-contents | git -C src hash-object --stdin -w) &&
178 git -C src tag myblob "$BLOB" &&
180 git clone --filter="blob:none" "file://$(pwd)/src" dst 2>err &&
181 ! grep "does not point to a valid object" err &&
185 . "$TEST_DIRECTORY"/lib-httpd.sh
188 # Converts bytes into a form suitable for inclusion in a sed command. For
189 # example, "printf 'ab\r\n' | hex_unpack" results in '\x61\x62\x0d\x0a'.
191 perl -e '$/ = undef; $input = <>; print unpack("H2" x length($input), $input)' |
192 sed 's/\(..\)/\\x\1/g'
195 test_expect_success 'upon cloning, check that all refs point to objects' '
196 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
197 rm -rf "$SERVER" repo &&
198 test_create_repo "$SERVER" &&
199 test_commit -C "$SERVER" foo &&
200 test_config -C "$SERVER" uploadpack.allowfilter 1 &&
201 test_config -C "$SERVER" uploadpack.allowanysha1inwant 1 &&
203 # Create a tag pointing to a blob.
204 BLOB=$(echo blob-contents | git -C "$SERVER" hash-object --stdin -w) &&
205 git -C "$SERVER" tag myblob "$BLOB" &&
207 # Craft a packfile not including that blob.
208 git -C "$SERVER" rev-parse HEAD |
209 git -C "$SERVER" pack-objects --stdout >incomplete.pack &&
211 # Replace the existing packfile with the crafted one. The protocol
212 # requires that the packfile be sent in sideband 1, hence the extra
213 # \x01 byte at the beginning.
214 printf "1,/packfile/!c %04x\\\\x01%s0000" \
215 "$(($(wc -c <incomplete.pack) + 5))" \
216 "$(sed_escape <incomplete.pack)" \
217 >"$HTTPD_ROOT_PATH/one-time-sed" &&
219 # Use protocol v2 because the sed command looks for the "packfile"
221 test_config -C "$SERVER" protocol.version 2 &&
222 test_must_fail git -c protocol.version=2 clone \
223 --filter=blob:none $HTTPD_URL/one_time_sed/server repo 2>err &&
225 grep "did not send all necessary objects" err &&
227 # Ensure that the one-time-sed script was used.
228 ! test -e "$HTTPD_ROOT_PATH/one-time-sed"
231 test_expect_success 'when partial cloning, tolerate server not sending target of tag' '
232 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
233 rm -rf "$SERVER" repo &&
234 test_create_repo "$SERVER" &&
235 test_commit -C "$SERVER" foo &&
236 test_config -C "$SERVER" uploadpack.allowfilter 1 &&
237 test_config -C "$SERVER" uploadpack.allowanysha1inwant 1 &&
239 # Create an annotated tag pointing to a blob.
240 BLOB=$(echo blob-contents | git -C "$SERVER" hash-object --stdin -w) &&
241 git -C "$SERVER" tag -m message -a myblob "$BLOB" &&
243 # Craft a packfile including the tag, but not the blob it points to.
244 # Also, omit objects referenced from HEAD in order to force a second
245 # fetch (to fetch missing objects) upon the automatic checkout that
246 # happens after a clone.
247 printf "%s\n%s\n--not\n%s\n%s\n" \
248 $(git -C "$SERVER" rev-parse HEAD) \
249 $(git -C "$SERVER" rev-parse myblob) \
250 $(git -C "$SERVER" rev-parse HEAD^{tree}) \
251 $(git -C "$SERVER" rev-parse myblob^{blob}) |
252 git -C "$SERVER" pack-objects --thin --stdout >incomplete.pack &&
254 # Replace the existing packfile with the crafted one. The protocol
255 # requires that the packfile be sent in sideband 1, hence the extra
256 # \x01 byte at the beginning.
257 printf "1,/packfile/!c %04x\\\\x01%s0000" \
258 "$(($(wc -c <incomplete.pack) + 5))" \
259 "$(sed_escape <incomplete.pack)" \
260 >"$HTTPD_ROOT_PATH/one-time-sed" &&
262 # Use protocol v2 because the sed command looks for the "packfile"
264 test_config -C "$SERVER" protocol.version 2 &&
266 # Exercise to make sure it works.
267 git -c protocol.version=2 clone \
268 --filter=blob:none $HTTPD_URL/one_time_sed/server repo 2> err &&
269 ! grep "missing object referenced by" err &&
271 # Ensure that the one-time-sed script was used.
272 ! test -e "$HTTPD_ROOT_PATH/one-time-sed"