f4eec0ba84
The test for "no shallow lines after receiving ACK ready" is very
sensitive to the timestamps of the commits we create. It's looking for
the fetch negotiation to send a "ready", which in turn depends on the
order in which we traverse commits during the negotiation.
It works reliably now because the base commit "7" is created without
test_commit, and thus gets a commit time matching the current system
clock. Whereas the new commits created in this test do use test_commit,
and get the usual test_tick time from 2005. So the fetch into the
"clone" repository results in a commit graph like this (I omitted some
of the "unrelated" commits for clarity; they're all just a sequence of
test_ticks):
$ git log --graph --format='%ct %s %d'
* 1112912953 new (origin/master, origin/HEAD)
* 1594322236 7 (grafted, master)
* 1112912893 unrelated15 (origin/unrelated15, unrelated15)
[...]
* 1112912053 unrelated1 (origin/unrelated1, unrelated1)
* 1112911993 new-too (HEAD -> newnew, tag: new-too)
The important things to see are:
- "7" is way in the future compared to the other commits
- "new-too" in the fetching repo is older than "new" (and its
"unrelated" ancestors) in the shallow repo
If we change our "setup shallow clone" step to use test_tick, too (and
get rid of the dependency on the system clock), then the test will fail.
The resulting graph looks like this:
$ git log --graph --format='%ct %s %d'
* 1112913373 new (origin/master, origin/HEAD)
* 1112912353 7 (grafted, master)
* 1112913313 unrelated15 (origin/unrelated15, unrelated15)
[...]
* 1112912473 unrelated1 (origin/unrelated1, unrelated1)
* 1112912413 new-too (HEAD -> newnew, tag: new-too)
Our "new-too" is still older than "new" and "unrelated", but now "7" is
older than all of them (because it advanced test_tick, which the other
tests built on top of). In the original, we advertised "7" as the first
"have" before anything else, but now "new-too" is more recent. You'd see
the same thing in the unlikely event that the system clock was set
before our test_tick default in 2005.
Let's make the timing requirements more explicit. The important thing is
that the client advertise all of its shared commits first, before
presenting its unique "new-too" commit. We can do that and get rid of
the system clock dependency at the same time by creating all of the
shared commits around time X (using test_tick), and then creating
"new-too" with some time long before X. The resulting graph looks like
this:
$ git log --graph --format='%ct %s %d'
* 1500001380 new (origin/master, origin/HEAD)
* 1500000420 7 (grafted, master)
* 1500001320 unrelated15 (origin/unrelated15, unrelated15)
[...]
* 1500000480 unrelated1 (origin/unrelated1, unrelated1)
* 1400000060 new-too (HEAD -> newnew, tag: new-too)
That also lets us get rid of the hacky test_tick added by f0e802ca20
(t5539: update a flaky test, 2014-07-14). That was clearly dancing
around the same problem, but only addressed the relationship between
commits created in the two subshells (which did use test_tick, but
overlapped because increments of test_tick in subshells are lost). Now
that we're using consistent and well-placed times for both lines of
history, we don't have to care about a one-tick difference between the
two sides.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
155 lines
4.1 KiB
Bash
Executable File
155 lines
4.1 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
test_description='fetch/clone from a shallow clone over http'
|
|
|
|
. ./test-lib.sh
|
|
. "$TEST_DIRECTORY"/lib-httpd.sh
|
|
start_httpd
|
|
|
|
commit() {
|
|
echo "$1" >tracked &&
|
|
git add tracked &&
|
|
test_tick &&
|
|
git commit -m "$1"
|
|
}
|
|
|
|
test_expect_success 'setup shallow clone' '
|
|
test_tick=1500000000 &&
|
|
commit 1 &&
|
|
commit 2 &&
|
|
commit 3 &&
|
|
commit 4 &&
|
|
commit 5 &&
|
|
commit 6 &&
|
|
commit 7 &&
|
|
git clone --no-local --depth=5 .git shallow &&
|
|
git config --global transfer.fsckObjects true
|
|
'
|
|
|
|
test_expect_success 'clone http repository' '
|
|
git clone --bare --no-local shallow "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
|
|
git clone $HTTPD_URL/smart/repo.git clone &&
|
|
(
|
|
cd clone &&
|
|
git fsck &&
|
|
git log --format=%s origin/master >actual &&
|
|
cat <<EOF >expect &&
|
|
7
|
|
6
|
|
5
|
|
4
|
|
3
|
|
EOF
|
|
test_cmp expect actual
|
|
)
|
|
'
|
|
|
|
# This test is tricky. We need large enough "have"s that fetch-pack
|
|
# will put pkt-flush in between. Then we need a "have" the server
|
|
# does not have, it'll send "ACK %s ready"
|
|
test_expect_success 'no shallow lines after receiving ACK ready' '
|
|
(
|
|
cd shallow &&
|
|
for i in $(test_seq 15)
|
|
do
|
|
git checkout --orphan unrelated$i &&
|
|
test_commit unrelated$i &&
|
|
git push -q "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
|
|
refs/heads/unrelated$i:refs/heads/unrelated$i &&
|
|
git push -q ../clone/.git \
|
|
refs/heads/unrelated$i:refs/heads/unrelated$i ||
|
|
exit 1
|
|
done &&
|
|
git checkout master &&
|
|
test_commit new &&
|
|
git push "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" master
|
|
) &&
|
|
(
|
|
cd clone &&
|
|
git checkout --orphan newnew &&
|
|
test_tick=1400000000 &&
|
|
test_commit new-too &&
|
|
# NEEDSWORK: If the overspecification of the expected result is reduced, we
|
|
# might be able to run this test in all protocol versions.
|
|
GIT_TRACE_PACKET="$TRASH_DIRECTORY/trace" GIT_TEST_PROTOCOL_VERSION=0 \
|
|
git fetch --depth=2 &&
|
|
grep "fetch-pack< ACK .* ready" ../trace &&
|
|
! grep "fetch-pack> done" ../trace
|
|
)
|
|
'
|
|
|
|
test_expect_success 'clone shallow since ...' '
|
|
test_create_repo shallow-since &&
|
|
(
|
|
cd shallow-since &&
|
|
GIT_COMMITTER_DATE="100000000 +0700" git commit --allow-empty -m one &&
|
|
GIT_COMMITTER_DATE="200000000 +0700" git commit --allow-empty -m two &&
|
|
GIT_COMMITTER_DATE="300000000 +0700" git commit --allow-empty -m three &&
|
|
mv .git "$HTTPD_DOCUMENT_ROOT_PATH/shallow-since.git" &&
|
|
git clone --shallow-since "300000000 +0700" $HTTPD_URL/smart/shallow-since.git ../shallow11 &&
|
|
git -C ../shallow11 log --pretty=tformat:%s HEAD >actual &&
|
|
echo three >expected &&
|
|
test_cmp expected actual
|
|
)
|
|
'
|
|
|
|
test_expect_success 'fetch shallow since ...' '
|
|
git -C shallow11 fetch --shallow-since "200000000 +0700" origin &&
|
|
git -C shallow11 log --pretty=tformat:%s origin/master >actual &&
|
|
cat >expected <<-\EOF &&
|
|
three
|
|
two
|
|
EOF
|
|
test_cmp expected actual
|
|
'
|
|
|
|
test_expect_success 'shallow clone exclude tag two' '
|
|
test_create_repo shallow-exclude &&
|
|
(
|
|
cd shallow-exclude &&
|
|
test_commit one &&
|
|
test_commit two &&
|
|
test_commit three &&
|
|
mv .git "$HTTPD_DOCUMENT_ROOT_PATH/shallow-exclude.git" &&
|
|
git clone --shallow-exclude two $HTTPD_URL/smart/shallow-exclude.git ../shallow12 &&
|
|
git -C ../shallow12 log --pretty=tformat:%s HEAD >actual &&
|
|
echo three >expected &&
|
|
test_cmp expected actual
|
|
)
|
|
'
|
|
|
|
test_expect_success 'fetch exclude tag one' '
|
|
git -C shallow12 fetch --shallow-exclude one origin &&
|
|
git -C shallow12 log --pretty=tformat:%s origin/master >actual &&
|
|
test_write_lines three two >expected &&
|
|
test_cmp expected actual
|
|
'
|
|
|
|
test_expect_success 'fetching deepen' '
|
|
test_create_repo shallow-deepen &&
|
|
(
|
|
cd shallow-deepen &&
|
|
test_commit one &&
|
|
test_commit two &&
|
|
test_commit three &&
|
|
mv .git "$HTTPD_DOCUMENT_ROOT_PATH/shallow-deepen.git" &&
|
|
git clone --depth 1 $HTTPD_URL/smart/shallow-deepen.git deepen &&
|
|
mv "$HTTPD_DOCUMENT_ROOT_PATH/shallow-deepen.git" .git &&
|
|
test_commit four &&
|
|
git -C deepen log --pretty=tformat:%s master >actual &&
|
|
echo three >expected &&
|
|
test_cmp expected actual &&
|
|
mv .git "$HTTPD_DOCUMENT_ROOT_PATH/shallow-deepen.git" &&
|
|
git -C deepen fetch --deepen=1 &&
|
|
git -C deepen log --pretty=tformat:%s origin/master >actual &&
|
|
cat >expected <<-\EOF &&
|
|
four
|
|
three
|
|
two
|
|
EOF
|
|
test_cmp expected actual
|
|
)
|
|
'
|
|
|
|
test_done
|