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