2017-12-08 15:58:49 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='git partial clone'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
# create a normal "src" repo where we can later create new commits.
|
|
|
|
# expect_1.oids will contain a list of the OIDs of all blobs.
|
|
|
|
test_expect_success 'setup normal src repo' '
|
|
|
|
echo "{print \$1}" >print_1.awk &&
|
|
|
|
echo "{print \$2}" >print_2.awk &&
|
|
|
|
|
|
|
|
git init src &&
|
|
|
|
for n in 1 2 3 4
|
|
|
|
do
|
|
|
|
echo "This is file: $n" > src/file.$n.txt
|
|
|
|
git -C src add file.$n.txt
|
|
|
|
git -C src commit -m "file $n"
|
|
|
|
git -C src ls-files -s file.$n.txt >>temp
|
|
|
|
done &&
|
|
|
|
awk -f print_2.awk <temp | sort >expect_1.oids &&
|
|
|
|
test_line_count = 4 expect_1.oids
|
|
|
|
'
|
|
|
|
|
|
|
|
# bare clone "src" giving "srv.bare" for use as our server.
|
|
|
|
test_expect_success 'setup bare clone for server' '
|
|
|
|
git clone --bare "file://$(pwd)/src" srv.bare &&
|
|
|
|
git -C srv.bare config --local uploadpack.allowfilter 1 &&
|
|
|
|
git -C srv.bare config --local uploadpack.allowanysha1inwant 1
|
|
|
|
'
|
|
|
|
|
|
|
|
# do basic partial clone from "srv.bare"
|
|
|
|
# confirm we are missing all of the known blobs.
|
|
|
|
# confirm partial clone was registered in the local config.
|
|
|
|
test_expect_success 'do partial clone 1' '
|
|
|
|
git clone --no-checkout --filter=blob:none "file://$(pwd)/srv.bare" pc1 &&
|
2018-10-05 21:54:03 +00:00
|
|
|
|
2018-10-05 21:54:07 +00:00
|
|
|
git -C pc1 rev-list --quiet --objects --missing=print HEAD >revs &&
|
2018-10-05 21:54:05 +00:00
|
|
|
awk -f print_1.awk revs |
|
2018-10-05 21:54:03 +00:00
|
|
|
sed "s/?//" |
|
|
|
|
sort >observed.oids &&
|
|
|
|
|
2017-12-08 15:58:49 +00:00
|
|
|
test_cmp expect_1.oids observed.oids &&
|
|
|
|
test "$(git -C pc1 config --local core.repositoryformatversion)" = "1" &&
|
|
|
|
test "$(git -C pc1 config --local extensions.partialclone)" = "origin" &&
|
|
|
|
test "$(git -C pc1 config --local core.partialclonefilter)" = "blob:none"
|
|
|
|
'
|
|
|
|
|
|
|
|
# checkout master to force dynamic object fetch of blobs at HEAD.
|
|
|
|
test_expect_success 'verify checkout with dynamic object fetch' '
|
2018-10-05 21:54:07 +00:00
|
|
|
git -C pc1 rev-list --quiet --objects --missing=print HEAD >observed &&
|
2017-12-08 15:58:49 +00:00
|
|
|
test_line_count = 4 observed &&
|
|
|
|
git -C pc1 checkout master &&
|
2018-10-05 21:54:07 +00:00
|
|
|
git -C pc1 rev-list --quiet --objects --missing=print HEAD >observed &&
|
2017-12-08 15:58:49 +00:00
|
|
|
test_line_count = 0 observed
|
|
|
|
'
|
|
|
|
|
|
|
|
# create new commits in "src" repo to establish a blame history on file.1.txt
|
|
|
|
# and push to "srv.bare".
|
|
|
|
test_expect_success 'push new commits to server' '
|
|
|
|
git -C src remote add srv "file://$(pwd)/srv.bare" &&
|
|
|
|
for x in a b c d e
|
|
|
|
do
|
2017-12-08 15:58:50 +00:00
|
|
|
echo "Mod file.1.txt $x" >>src/file.1.txt
|
2017-12-08 15:58:49 +00:00
|
|
|
git -C src add file.1.txt
|
|
|
|
git -C src commit -m "mod $x"
|
|
|
|
done &&
|
|
|
|
git -C src blame master -- file.1.txt >expect.blame &&
|
|
|
|
git -C src push -u srv master
|
|
|
|
'
|
|
|
|
|
|
|
|
# (partial) fetch in the partial clone repo from the promisor remote.
|
|
|
|
# verify that fetch inherited the filter-spec from the config and DOES NOT
|
|
|
|
# have the new blobs.
|
|
|
|
test_expect_success 'partial fetch inherits filter settings' '
|
|
|
|
git -C pc1 fetch origin &&
|
2018-10-05 21:54:07 +00:00
|
|
|
git -C pc1 rev-list --quiet --objects --missing=print \
|
|
|
|
master..origin/master >observed &&
|
2017-12-08 15:58:49 +00:00
|
|
|
test_line_count = 5 observed
|
|
|
|
'
|
|
|
|
|
|
|
|
# force dynamic object fetch using diff.
|
|
|
|
# we should only get 1 new blob (for the file in origin/master).
|
|
|
|
test_expect_success 'verify diff causes dynamic object fetch' '
|
|
|
|
git -C pc1 diff master..origin/master -- file.1.txt &&
|
2018-10-05 21:54:07 +00:00
|
|
|
git -C pc1 rev-list --quiet --objects --missing=print \
|
|
|
|
master..origin/master >observed &&
|
2017-12-08 15:58:49 +00:00
|
|
|
test_line_count = 4 observed
|
|
|
|
'
|
|
|
|
|
|
|
|
# force full dynamic object fetch of the file's history using blame.
|
|
|
|
# we should get the intermediate blobs for the file.
|
|
|
|
test_expect_success 'verify blame causes dynamic object fetch' '
|
|
|
|
git -C pc1 blame origin/master -- file.1.txt >observed.blame &&
|
|
|
|
test_cmp expect.blame observed.blame &&
|
2018-10-05 21:54:07 +00:00
|
|
|
git -C pc1 rev-list --quiet --objects --missing=print \
|
|
|
|
master..origin/master >observed &&
|
2017-12-08 15:58:49 +00:00
|
|
|
test_line_count = 0 observed
|
|
|
|
'
|
|
|
|
|
2017-12-08 15:58:50 +00:00
|
|
|
# create new commits in "src" repo to establish a history on file.2.txt
|
|
|
|
# and push to "srv.bare".
|
|
|
|
test_expect_success 'push new commits to server for file.2.txt' '
|
|
|
|
for x in a b c d e f
|
|
|
|
do
|
|
|
|
echo "Mod file.2.txt $x" >>src/file.2.txt
|
|
|
|
git -C src add file.2.txt
|
|
|
|
git -C src commit -m "mod $x"
|
|
|
|
done &&
|
|
|
|
git -C src push -u srv master
|
|
|
|
'
|
|
|
|
|
2017-12-08 15:58:51 +00:00
|
|
|
# Do FULL fetch by disabling inherited filter-spec using --no-filter.
|
2017-12-08 15:58:50 +00:00
|
|
|
# Verify we have all the new blobs.
|
|
|
|
test_expect_success 'override inherited filter-spec using --no-filter' '
|
|
|
|
git -C pc1 fetch --no-filter origin &&
|
2018-10-05 21:54:07 +00:00
|
|
|
git -C pc1 rev-list --quiet --objects --missing=print \
|
|
|
|
master..origin/master >observed &&
|
2017-12-08 15:58:50 +00:00
|
|
|
test_line_count = 0 observed
|
|
|
|
'
|
|
|
|
|
2017-12-08 15:58:51 +00:00
|
|
|
# create new commits in "src" repo to establish a history on file.3.txt
|
|
|
|
# and push to "srv.bare".
|
|
|
|
test_expect_success 'push new commits to server for file.3.txt' '
|
|
|
|
for x in a b c d e f
|
|
|
|
do
|
|
|
|
echo "Mod file.3.txt $x" >>src/file.3.txt
|
|
|
|
git -C src add file.3.txt
|
|
|
|
git -C src commit -m "mod $x"
|
|
|
|
done &&
|
|
|
|
git -C src push -u srv master
|
|
|
|
'
|
|
|
|
|
|
|
|
# Do a partial fetch and then try to manually fetch the missing objects.
|
|
|
|
# This can be used as the basis of a pre-command hook to bulk fetch objects
|
|
|
|
# perhaps combined with a command in dry-run mode.
|
|
|
|
test_expect_success 'manual prefetch of missing objects' '
|
|
|
|
git -C pc1 fetch --filter=blob:none origin &&
|
2018-10-05 21:54:03 +00:00
|
|
|
|
2018-10-05 21:54:07 +00:00
|
|
|
git -C pc1 rev-list --quiet --objects --missing=print \
|
|
|
|
master..origin/master >revs &&
|
2018-10-05 21:54:05 +00:00
|
|
|
awk -f print_1.awk revs |
|
2018-10-05 21:54:03 +00:00
|
|
|
sed "s/?//" |
|
|
|
|
sort >observed.oids &&
|
|
|
|
|
2017-12-08 15:58:51 +00:00
|
|
|
test_line_count = 6 observed.oids &&
|
|
|
|
git -C pc1 fetch-pack --stdin "file://$(pwd)/srv.bare" <observed.oids &&
|
2018-10-05 21:54:03 +00:00
|
|
|
|
2018-10-05 21:54:07 +00:00
|
|
|
git -C pc1 rev-list --quiet --objects --missing=print \
|
|
|
|
master..origin/master >revs &&
|
2018-10-05 21:54:05 +00:00
|
|
|
awk -f print_1.awk revs |
|
2018-10-05 21:54:03 +00:00
|
|
|
sed "s/?//" |
|
|
|
|
sort >observed.oids &&
|
|
|
|
|
2017-12-08 15:58:51 +00:00
|
|
|
test_line_count = 0 observed.oids
|
|
|
|
'
|
|
|
|
|
2018-03-14 18:42:41 +00:00
|
|
|
test_expect_success 'partial clone with transfer.fsckobjects=1 uses index-pack --fsck-objects' '
|
|
|
|
git init src &&
|
|
|
|
test_commit -C src x &&
|
|
|
|
test_config -C src uploadpack.allowfilter 1 &&
|
|
|
|
test_config -C src uploadpack.allowanysha1inwant 1 &&
|
|
|
|
|
|
|
|
GIT_TRACE="$(pwd)/trace" git -c transfer.fsckobjects=1 \
|
|
|
|
clone --filter="blob:none" "file://$(pwd)/src" dst &&
|
|
|
|
grep "git index-pack.*--fsck-objects" trace
|
|
|
|
'
|
|
|
|
|
2018-07-06 19:34:09 +00:00
|
|
|
test_expect_success 'partial clone fetches blobs pointed to by refs even if normally filtered out' '
|
|
|
|
rm -rf src dst &&
|
|
|
|
git init src &&
|
|
|
|
test_commit -C src x &&
|
|
|
|
test_config -C src uploadpack.allowfilter 1 &&
|
|
|
|
test_config -C src uploadpack.allowanysha1inwant 1 &&
|
|
|
|
|
|
|
|
# Create a tag pointing to a blob.
|
|
|
|
BLOB=$(echo blob-contents | git -C src hash-object --stdin -w) &&
|
|
|
|
git -C src tag myblob "$BLOB" &&
|
|
|
|
|
|
|
|
git clone --filter="blob:none" "file://$(pwd)/src" dst 2>err &&
|
|
|
|
! grep "does not point to a valid object" err &&
|
|
|
|
git -C dst fsck
|
|
|
|
'
|
|
|
|
|
2018-07-06 19:34:10 +00:00
|
|
|
. "$TEST_DIRECTORY"/lib-httpd.sh
|
|
|
|
start_httpd
|
|
|
|
|
|
|
|
# Converts bytes into a form suitable for inclusion in a sed command. For
|
|
|
|
# example, "printf 'ab\r\n' | hex_unpack" results in '\x61\x62\x0d\x0a'.
|
|
|
|
sed_escape () {
|
|
|
|
perl -e '$/ = undef; $input = <>; print unpack("H2" x length($input), $input)' |
|
|
|
|
sed 's/\(..\)/\\x\1/g'
|
|
|
|
}
|
|
|
|
|
|
|
|
test_expect_success 'upon cloning, check that all refs point to objects' '
|
|
|
|
SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
|
|
|
|
rm -rf "$SERVER" repo &&
|
|
|
|
test_create_repo "$SERVER" &&
|
|
|
|
test_commit -C "$SERVER" foo &&
|
|
|
|
test_config -C "$SERVER" uploadpack.allowfilter 1 &&
|
|
|
|
test_config -C "$SERVER" uploadpack.allowanysha1inwant 1 &&
|
|
|
|
|
|
|
|
# Create a tag pointing to a blob.
|
|
|
|
BLOB=$(echo blob-contents | git -C "$SERVER" hash-object --stdin -w) &&
|
|
|
|
git -C "$SERVER" tag myblob "$BLOB" &&
|
|
|
|
|
|
|
|
# Craft a packfile not including that blob.
|
|
|
|
git -C "$SERVER" rev-parse HEAD |
|
2018-10-05 21:54:03 +00:00
|
|
|
git -C "$SERVER" pack-objects --stdout >incomplete.pack &&
|
2018-07-06 19:34:10 +00:00
|
|
|
|
|
|
|
# Replace the existing packfile with the crafted one. The protocol
|
|
|
|
# requires that the packfile be sent in sideband 1, hence the extra
|
|
|
|
# \x01 byte at the beginning.
|
|
|
|
printf "1,/packfile/!c %04x\\\\x01%s0000" \
|
|
|
|
"$(($(wc -c <incomplete.pack) + 5))" \
|
|
|
|
"$(sed_escape <incomplete.pack)" \
|
|
|
|
>"$HTTPD_ROOT_PATH/one-time-sed" &&
|
|
|
|
|
|
|
|
# Use protocol v2 because the sed command looks for the "packfile"
|
|
|
|
# section header.
|
|
|
|
test_config -C "$SERVER" protocol.version 2 &&
|
|
|
|
test_must_fail git -c protocol.version=2 clone \
|
|
|
|
--filter=blob:none $HTTPD_URL/one_time_sed/server repo 2>err &&
|
|
|
|
|
|
|
|
grep "did not send all necessary objects" err &&
|
|
|
|
|
|
|
|
# Ensure that the one-time-sed script was used.
|
|
|
|
! test -e "$HTTPD_ROOT_PATH/one-time-sed"
|
|
|
|
'
|
|
|
|
|
2018-07-13 00:03:06 +00:00
|
|
|
test_expect_success 'when partial cloning, tolerate server not sending target of tag' '
|
|
|
|
SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
|
|
|
|
rm -rf "$SERVER" repo &&
|
|
|
|
test_create_repo "$SERVER" &&
|
|
|
|
test_commit -C "$SERVER" foo &&
|
|
|
|
test_config -C "$SERVER" uploadpack.allowfilter 1 &&
|
|
|
|
test_config -C "$SERVER" uploadpack.allowanysha1inwant 1 &&
|
|
|
|
|
|
|
|
# Create an annotated tag pointing to a blob.
|
|
|
|
BLOB=$(echo blob-contents | git -C "$SERVER" hash-object --stdin -w) &&
|
|
|
|
git -C "$SERVER" tag -m message -a myblob "$BLOB" &&
|
|
|
|
|
|
|
|
# Craft a packfile including the tag, but not the blob it points to.
|
2018-07-13 00:03:07 +00:00
|
|
|
# Also, omit objects referenced from HEAD in order to force a second
|
|
|
|
# fetch (to fetch missing objects) upon the automatic checkout that
|
|
|
|
# happens after a clone.
|
|
|
|
printf "%s\n%s\n--not\n%s\n%s\n" \
|
2018-07-13 00:03:06 +00:00
|
|
|
$(git -C "$SERVER" rev-parse HEAD) \
|
|
|
|
$(git -C "$SERVER" rev-parse myblob) \
|
2018-07-13 00:03:07 +00:00
|
|
|
$(git -C "$SERVER" rev-parse HEAD^{tree}) \
|
2018-07-13 00:03:06 +00:00
|
|
|
$(git -C "$SERVER" rev-parse myblob^{blob}) |
|
|
|
|
git -C "$SERVER" pack-objects --thin --stdout >incomplete.pack &&
|
|
|
|
|
|
|
|
# Replace the existing packfile with the crafted one. The protocol
|
|
|
|
# requires that the packfile be sent in sideband 1, hence the extra
|
|
|
|
# \x01 byte at the beginning.
|
|
|
|
printf "1,/packfile/!c %04x\\\\x01%s0000" \
|
|
|
|
"$(($(wc -c <incomplete.pack) + 5))" \
|
|
|
|
"$(sed_escape <incomplete.pack)" \
|
|
|
|
>"$HTTPD_ROOT_PATH/one-time-sed" &&
|
|
|
|
|
|
|
|
# Use protocol v2 because the sed command looks for the "packfile"
|
|
|
|
# section header.
|
|
|
|
test_config -C "$SERVER" protocol.version 2 &&
|
|
|
|
|
|
|
|
# Exercise to make sure it works.
|
|
|
|
git -c protocol.version=2 clone \
|
2018-07-13 00:03:07 +00:00
|
|
|
--filter=blob:none $HTTPD_URL/one_time_sed/server repo 2> err &&
|
|
|
|
! grep "missing object referenced by" err &&
|
2018-07-13 00:03:06 +00:00
|
|
|
|
|
|
|
# Ensure that the one-time-sed script was used.
|
|
|
|
! test -e "$HTTPD_ROOT_PATH/one-time-sed"
|
|
|
|
'
|
|
|
|
|
2018-07-06 19:34:10 +00:00
|
|
|
stop_httpd
|
|
|
|
|
2017-12-08 15:58:49 +00:00
|
|
|
test_done
|