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