]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5537-fetch-shallow.sh
The sixth batch
[thirdparty/git.git] / t / t5537-fetch-shallow.sh
CommitLineData
4820a33b
NTND
1#!/bin/sh
2
3test_description='fetch/clone from a shallow clone'
4
5. ./test-lib.sh
6
7commit() {
8 echo "$1" >tracked &&
9 git add tracked &&
10 git commit -m "$1"
11}
12
13test_expect_success 'setup' '
14 commit 1 &&
15 commit 2 &&
16 commit 3 &&
17 commit 4 &&
a8c17e3b 18 git config --global transfer.fsckObjects true &&
8a8da497 19 test_oid_cache <<-\EOF
0d65f3fb
JS
20 perl sha1:s/0034shallow %s/0036unshallow %s/
21 perl sha256:s/004cshallow %s/004eunshallow %s/
a8c17e3b 22 EOF
4820a33b
NTND
23'
24
25test_expect_success 'setup shallow clone' '
26 git clone --no-local --depth=2 .git shallow &&
27 git --git-dir=shallow/.git log --format=%s >actual &&
8a8da497 28 test_write_lines 4 3 >expect &&
4820a33b
NTND
29 test_cmp expect actual
30'
31
32test_expect_success 'clone from shallow clone' '
33 git clone --no-local shallow shallow2 &&
34 (
35 cd shallow2 &&
36 git fsck &&
37 git log --format=%s >actual &&
8a8da497 38 test_write_lines 4 3 >expect &&
4820a33b
NTND
39 test_cmp expect actual
40 )
41'
42
43test_expect_success 'fetch from shallow clone' '
44 (
45 cd shallow &&
46 commit 5
47 ) &&
48 (
49 cd shallow2 &&
50 git fetch &&
51 git fsck &&
52 git log --format=%s origin/master >actual &&
8a8da497 53 test_write_lines 5 4 3 >expect &&
4820a33b
NTND
54 test_cmp expect actual
55 )
56'
57
58test_expect_success 'fetch --depth from shallow clone' '
59 (
60 cd shallow &&
61 commit 6
62 ) &&
63 (
64 cd shallow2 &&
65 git fetch --depth=2 &&
66 git fsck &&
67 git log --format=%s origin/master >actual &&
8a8da497 68 test_write_lines 6 5 >expect &&
4820a33b
NTND
69 test_cmp expect actual
70 )
71'
72
79d3a236
NTND
73test_expect_success 'fetch --unshallow from shallow clone' '
74 (
75 cd shallow2 &&
76 git fetch --unshallow &&
77 git fsck &&
78 git log --format=%s origin/master >actual &&
8a8da497 79 test_write_lines 6 5 4 3 >expect &&
79d3a236
NTND
80 test_cmp expect actual
81 )
82'
83
4820a33b
NTND
84test_expect_success 'fetch something upstream has but hidden by clients shallow boundaries' '
85 # the blob "1" is available in .git but hidden by the
86 # shallow2/.git/shallow and it should be resent
e3a75be3 87 ! git --git-dir=shallow2/.git cat-file blob $(echo 1|git hash-object --stdin) >/dev/null &&
4820a33b
NTND
88 echo 1 >1.t &&
89 git add 1.t &&
90 git commit -m add-1-back &&
91 (
92 cd shallow2 &&
93 git fetch ../.git +refs/heads/master:refs/remotes/top/master &&
94 git fsck &&
95 git log --format=%s top/master >actual &&
8a8da497 96 test_write_lines add-1-back 4 3 >expect &&
4820a33b
NTND
97 test_cmp expect actual
98 ) &&
e3a75be3 99 git --git-dir=shallow2/.git cat-file blob $(echo 1|git hash-object --stdin) >/dev/null
4820a33b
NTND
100'
101
102test_expect_success 'fetch that requires changes in .git/shallow is filtered' '
103 (
104 cd shallow &&
105 git checkout --orphan no-shallow &&
106 commit no-shallow
107 ) &&
108 git init notshallow &&
109 (
110 cd notshallow &&
64d1022e 111 git fetch ../shallow/.git refs/heads/*:refs/remotes/shallow/* &&
4820a33b 112 git for-each-ref --format="%(refname)" >actual.refs &&
8a8da497 113 echo refs/remotes/shallow/no-shallow >expect.refs &&
4820a33b
NTND
114 test_cmp expect.refs actual.refs &&
115 git log --format=%s shallow/no-shallow >actual &&
8a8da497 116 echo no-shallow >expect &&
4820a33b
NTND
117 test_cmp expect actual
118 )
119'
120
48d25cae
NTND
121test_expect_success 'fetch --update-shallow' '
122 (
123 cd shallow &&
124 git checkout master &&
125 commit 7 &&
126 git tag -m foo heavy-tag HEAD^ &&
127 git tag light-tag HEAD^:tracked
128 ) &&
129 (
130 cd notshallow &&
131 git fetch --update-shallow ../shallow/.git refs/heads/*:refs/remotes/shallow/* &&
132 git fsck &&
133 git for-each-ref --sort=refname --format="%(refname)" >actual.refs &&
8a8da497
TB
134 cat <<-\EOF >expect.refs &&
135 refs/remotes/shallow/master
136 refs/remotes/shallow/no-shallow
137 refs/tags/heavy-tag
138 refs/tags/light-tag
139 EOF
48d25cae
NTND
140 test_cmp expect.refs actual.refs &&
141 git log --format=%s shallow/master >actual &&
8a8da497 142 test_write_lines 7 6 5 4 3 >expect &&
48d25cae
NTND
143 test_cmp expect actual
144 )
145'
146
37b9dcab
TB
147test_expect_success 'fetch --update-shallow (with fetch.writeCommitGraph)' '
148 (
149 cd shallow &&
150 git checkout master &&
151 commit 8 &&
152 git tag -m foo heavy-tag-for-graph HEAD^ &&
153 git tag light-tag-for-graph HEAD^:tracked
154 ) &&
155 test_config -C notshallow fetch.writeCommitGraph true &&
156 (
157 cd notshallow &&
158 git fetch --update-shallow ../shallow/.git refs/heads/*:refs/remotes/shallow/* &&
159 git fsck &&
160 git for-each-ref --sort=refname --format="%(refname)" >actual.refs &&
161 cat <<-EOF >expect.refs &&
162 refs/remotes/shallow/master
163 refs/remotes/shallow/no-shallow
164 refs/tags/heavy-tag
165 refs/tags/heavy-tag-for-graph
166 refs/tags/light-tag
167 refs/tags/light-tag-for-graph
168 EOF
48d25cae
NTND
169 test_cmp expect.refs actual.refs &&
170 git log --format=%s shallow/master >actual &&
37b9dcab 171 test_write_lines 8 7 6 5 4 3 >expect &&
48d25cae
NTND
172 test_cmp expect actual
173 )
174'
175
b790e0f6
NTND
176test_expect_success POSIXPERM,SANITY 'shallow fetch from a read-only repo' '
177 cp -R .git read-only.git &&
b790e0f6 178 test_when_finished "find read-only.git -type d -print | xargs chmod +w" &&
03771425 179 find read-only.git -print | xargs chmod -w &&
b790e0f6
NTND
180 git clone --no-local --depth=2 read-only.git from-read-only &&
181 git --git-dir=from-read-only/.git log --format=%s >actual &&
8a8da497 182 test_write_lines add-1-back 4 >expect &&
b790e0f6
NTND
183 test_cmp expect actual
184'
185
5dcfbf56 186test_expect_success '.git/shallow is edited by repack' '
328a4351
JS
187 git init shallow-server &&
188 test_commit -C shallow-server A &&
189 test_commit -C shallow-server B &&
190 git -C shallow-server checkout -b branch &&
191 test_commit -C shallow-server C &&
192 test_commit -C shallow-server E &&
193 test_commit -C shallow-server D &&
194 d="$(git -C shallow-server rev-parse --verify D^0)" &&
195 git -C shallow-server checkout master &&
196
197 git clone --depth=1 --no-tags --no-single-branch \
198 "file://$PWD/shallow-server" shallow-client &&
199
200 : now remove the branch and fetch with prune &&
201 git -C shallow-server branch -D branch &&
202 git -C shallow-client fetch --prune --depth=1 \
203 origin "+refs/heads/*:refs/remotes/origin/*" &&
204 git -C shallow-client repack -adfl &&
205 test_must_fail git -C shallow-client rev-parse --verify $d^0 &&
206 ! grep $d shallow-client/.git/shallow &&
207
208 git -C shallow-server branch branch-orig $d &&
209 git -C shallow-client fetch --prune --depth=2 \
210 origin "+refs/heads/*:refs/remotes/origin/*"
211'
212
cf1e7c07
JT
213. "$TEST_DIRECTORY"/lib-httpd.sh
214start_httpd
215
216REPO="$HTTPD_DOCUMENT_ROOT_PATH/repo"
217
218test_expect_success 'shallow fetches check connectivity before writing shallow file' '
219 rm -rf "$REPO" client &&
220
221 git init "$REPO" &&
222 test_commit -C "$REPO" one &&
223 test_commit -C "$REPO" two &&
224 test_commit -C "$REPO" three &&
225
226 git init client &&
227
228 # Use protocol v2 to ensure that shallow information is sent exactly
229 # once by the server, since we are planning to manipulate it.
230 git -C "$REPO" config protocol.version 2 &&
231 git -C client config protocol.version 2 &&
232
eafff6e4 233 git -C client fetch --depth=2 "$HTTPD_URL/one_time_perl/repo" master:a_branch &&
cf1e7c07
JT
234
235 # Craft a situation in which the server sends back an unshallow request
236 # with an empty packfile. This is done by refetching with a shorter
237 # depth (to ensure that the packfile is empty), and overwriting the
238 # shallow line in the response with the unshallow line we want.
0d65f3fb 239 printf "$(test_oid perl)" \
cf1e7c07
JT
240 "$(git -C "$REPO" rev-parse HEAD)" \
241 "$(git -C "$REPO" rev-parse HEAD^)" \
eafff6e4 242 >"$HTTPD_ROOT_PATH/one-time-perl" &&
07c3c2aa 243 test_must_fail env GIT_TEST_SIDEBAND_ALL=0 git -C client \
eafff6e4 244 fetch --depth=1 "$HTTPD_URL/one_time_perl/repo" \
cf1e7c07
JT
245 master:a_branch &&
246
eafff6e4
JS
247 # Ensure that the one-time-perl script was used.
248 ! test -e "$HTTPD_ROOT_PATH/one-time-perl" &&
cf1e7c07
JT
249
250 # Ensure that the resulting repo is consistent, despite our failure to
251 # fetch.
252 git -C client fsck
253'
254
decfe05b
SG
255# DO NOT add non-httpd-specific tests here, because the last part of this
256# test script is only executed when httpd is available and enabled.
257
4820a33b 258test_done