Merge branch 'es/worktree-repair-copied' into cw/worktrees-relative
[git/gitster.git] / t / t5539-fetch-http-shallow.sh
blob82fe09d0a9755499cbbf67726fa25f8ca00c45a7
1 #!/bin/sh
3 test_description='fetch/clone from a shallow clone over http'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
10 . "$TEST_DIRECTORY"/lib-httpd.sh
11 start_httpd
13 commit() {
14 echo "$1" >tracked &&
15 git add tracked &&
16 test_tick &&
17 git commit -m "$1"
20 test_expect_success 'setup shallow clone' '
21 test_tick=1500000000 &&
22 commit 1 &&
23 commit 2 &&
24 commit 3 &&
25 commit 4 &&
26 commit 5 &&
27 commit 6 &&
28 commit 7 &&
29 git clone --no-local --depth=5 .git shallow &&
30 git config --global transfer.fsckObjects true
33 test_expect_success 'clone http repository' '
34 git clone --bare --no-local shallow "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
35 git clone $HTTPD_URL/smart/repo.git clone &&
37 cd clone &&
38 git fsck &&
39 git log --format=%s origin/main >actual &&
40 cat <<EOF >expect &&
46 EOF
47 test_cmp expect actual
51 # This test is tricky. We need large enough "have"s that fetch-pack
52 # will put pkt-flush in between. Then we need a "have" the server
53 # does not have, it'll send "ACK %s ready"
54 test_expect_success 'no shallow lines after receiving ACK ready' '
56 cd shallow &&
57 for i in $(test_seq 15)
59 git checkout --orphan unrelated$i &&
60 test_commit unrelated$i &&
61 git push -q "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
62 refs/heads/unrelated$i:refs/heads/unrelated$i &&
63 git push -q ../clone/.git \
64 refs/heads/unrelated$i:refs/heads/unrelated$i ||
65 exit 1
66 done &&
67 git checkout main &&
68 test_commit new &&
69 git push "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" main
70 ) &&
72 cd clone &&
73 git checkout --orphan newnew &&
74 test_tick=1400000000 &&
75 test_commit new-too &&
76 # NEEDSWORK: If the overspecification of the expected result is reduced, we
77 # might be able to run this test in all protocol versions.
78 GIT_TRACE_PACKET="$TRASH_DIRECTORY/trace" GIT_TEST_PROTOCOL_VERSION=0 \
79 git fetch --depth=2 &&
80 grep "fetch-pack< ACK .* ready" ../trace &&
81 ! grep "fetch-pack> done" ../trace
85 test_expect_success 'clone shallow since ...' '
86 test_create_repo shallow-since &&
88 cd shallow-since &&
89 GIT_COMMITTER_DATE="100000000 +0700" git commit --allow-empty -m one &&
90 GIT_COMMITTER_DATE="200000000 +0700" git commit --allow-empty -m two &&
91 GIT_COMMITTER_DATE="300000000 +0700" git commit --allow-empty -m three &&
92 mv .git "$HTTPD_DOCUMENT_ROOT_PATH/shallow-since.git" &&
93 git clone --shallow-since "300000000 +0700" $HTTPD_URL/smart/shallow-since.git ../shallow11 &&
94 git -C ../shallow11 log --pretty=tformat:%s HEAD >actual &&
95 echo three >expected &&
96 test_cmp expected actual
100 test_expect_success 'fetch shallow since ...' '
101 git -C shallow11 fetch --shallow-since "200000000 +0700" origin &&
102 git -C shallow11 log --pretty=tformat:%s origin/main >actual &&
103 cat >expected <<-\EOF &&
104 three
107 test_cmp expected actual
110 test_expect_success 'shallow clone exclude tag two' '
111 test_create_repo shallow-exclude &&
113 cd shallow-exclude &&
114 test_commit one &&
115 test_commit two &&
116 test_commit three &&
117 mv .git "$HTTPD_DOCUMENT_ROOT_PATH/shallow-exclude.git" &&
118 git clone --shallow-exclude two $HTTPD_URL/smart/shallow-exclude.git ../shallow12 &&
119 git -C ../shallow12 log --pretty=tformat:%s HEAD >actual &&
120 echo three >expected &&
121 test_cmp expected actual
125 test_expect_success 'fetch exclude tag one' '
126 git -C shallow12 fetch --shallow-exclude one origin &&
127 git -C shallow12 log --pretty=tformat:%s origin/main >actual &&
128 test_write_lines three two >expected &&
129 test_cmp expected actual
132 test_expect_success 'fetching deepen' '
133 test_create_repo shallow-deepen &&
135 cd shallow-deepen &&
136 test_commit one &&
137 test_commit two &&
138 test_commit three &&
139 mv .git "$HTTPD_DOCUMENT_ROOT_PATH/shallow-deepen.git" &&
140 git clone --depth 1 $HTTPD_URL/smart/shallow-deepen.git deepen &&
141 mv "$HTTPD_DOCUMENT_ROOT_PATH/shallow-deepen.git" .git &&
142 test_commit four &&
143 git -C deepen log --pretty=tformat:%s main >actual &&
144 echo three >expected &&
145 test_cmp expected actual &&
146 mv .git "$HTTPD_DOCUMENT_ROOT_PATH/shallow-deepen.git" &&
147 git -C deepen fetch --deepen=1 &&
148 git -C deepen log --pretty=tformat:%s origin/main >actual &&
149 cat >expected <<-\EOF &&
150 four
151 three
154 test_cmp expected actual
158 test_done