t: fix whitespace around &&
[alt-git.git] / t / t5537-fetch-shallow.sh
blobb57209c84fcad43ce728dd8bfa24674caa64c37c
1 #!/bin/sh
3 test_description='fetch/clone from a shallow clone'
5 . ./test-lib.sh
7 commit() {
8 echo "$1" >tracked &&
9 git add tracked &&
10 git commit -m "$1"
13 test_expect_success 'setup' '
14 commit 1 &&
15 commit 2 &&
16 commit 3 &&
17 commit 4 &&
18 git config --global transfer.fsckObjects true &&
19 test_oid_cache <<-EOF
20 perl sha1:s/0034shallow %s/0036unshallow %s/
21 perl sha256:s/004cshallow %s/004eunshallow %s/
22 EOF
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 &&
28 cat <<EOF >expect &&
31 EOF
32 test_cmp expect actual
35 test_expect_success 'clone from shallow clone' '
36 git clone --no-local shallow shallow2 &&
38 cd shallow2 &&
39 git fsck &&
40 git log --format=%s >actual &&
41 cat <<EOF >expect &&
44 EOF
45 test_cmp expect actual
49 test_expect_success 'fetch from shallow clone' '
51 cd shallow &&
52 commit 5
53 ) &&
55 cd shallow2 &&
56 git fetch &&
57 git fsck &&
58 git log --format=%s origin/master >actual &&
59 cat <<EOF >expect &&
63 EOF
64 test_cmp expect actual
68 test_expect_success 'fetch --depth from shallow clone' '
70 cd shallow &&
71 commit 6
72 ) &&
74 cd shallow2 &&
75 git fetch --depth=2 &&
76 git fsck &&
77 git log --format=%s origin/master >actual &&
78 cat <<EOF >expect &&
81 EOF
82 test_cmp expect actual
86 test_expect_success 'fetch --unshallow from shallow clone' '
88 cd shallow2 &&
89 git fetch --unshallow &&
90 git fsck &&
91 git log --format=%s origin/master >actual &&
92 cat <<EOF >expect &&
97 EOF
98 test_cmp expect actual
102 test_expect_success 'fetch something upstream has but hidden by clients shallow boundaries' '
103 # the blob "1" is available in .git but hidden by the
104 # shallow2/.git/shallow and it should be resent
105 ! git --git-dir=shallow2/.git cat-file blob $(echo 1|git hash-object --stdin) >/dev/null &&
106 echo 1 >1.t &&
107 git add 1.t &&
108 git commit -m add-1-back &&
110 cd shallow2 &&
111 git fetch ../.git +refs/heads/master:refs/remotes/top/master &&
112 git fsck &&
113 git log --format=%s top/master >actual &&
114 cat <<EOF >expect &&
115 add-1-back
119 test_cmp expect actual
120 ) &&
121 git --git-dir=shallow2/.git cat-file blob $(echo 1|git hash-object --stdin) >/dev/null
125 test_expect_success 'fetch that requires changes in .git/shallow is filtered' '
127 cd shallow &&
128 git checkout --orphan no-shallow &&
129 commit no-shallow
130 ) &&
131 git init notshallow &&
133 cd notshallow &&
134 git fetch ../shallow/.git refs/heads/*:refs/remotes/shallow/* &&
135 git for-each-ref --format="%(refname)" >actual.refs &&
136 cat <<EOF >expect.refs &&
137 refs/remotes/shallow/no-shallow
139 test_cmp expect.refs actual.refs &&
140 git log --format=%s shallow/no-shallow >actual &&
141 cat <<EOF >expect &&
142 no-shallow
144 test_cmp expect actual
148 test_expect_success 'fetch --update-shallow' '
150 cd shallow &&
151 git checkout master &&
152 commit 7 &&
153 git tag -m foo heavy-tag HEAD^ &&
154 git tag light-tag HEAD^:tracked
155 ) &&
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/light-tag
167 test_cmp expect.refs actual.refs &&
168 git log --format=%s shallow/master >actual &&
169 cat <<EOF >expect &&
176 test_cmp expect actual
180 test_expect_success POSIXPERM,SANITY 'shallow fetch from a read-only repo' '
181 cp -R .git read-only.git &&
182 test_when_finished "find read-only.git -type d -print | xargs chmod +w" &&
183 find read-only.git -print | xargs chmod -w &&
184 git clone --no-local --depth=2 read-only.git from-read-only &&
185 git --git-dir=from-read-only/.git log --format=%s >actual &&
186 cat >expect <<EOF &&
187 add-1-back
190 test_cmp expect actual
193 test_expect_success '.git/shallow is edited by repack' '
194 git init shallow-server &&
195 test_commit -C shallow-server A &&
196 test_commit -C shallow-server B &&
197 git -C shallow-server checkout -b branch &&
198 test_commit -C shallow-server C &&
199 test_commit -C shallow-server E &&
200 test_commit -C shallow-server D &&
201 d="$(git -C shallow-server rev-parse --verify D^0)" &&
202 git -C shallow-server checkout master &&
204 git clone --depth=1 --no-tags --no-single-branch \
205 "file://$PWD/shallow-server" shallow-client &&
207 : now remove the branch and fetch with prune &&
208 git -C shallow-server branch -D branch &&
209 git -C shallow-client fetch --prune --depth=1 \
210 origin "+refs/heads/*:refs/remotes/origin/*" &&
211 git -C shallow-client repack -adfl &&
212 test_must_fail git -C shallow-client rev-parse --verify $d^0 &&
213 ! grep $d shallow-client/.git/shallow &&
215 git -C shallow-server branch branch-orig $d &&
216 git -C shallow-client fetch --prune --depth=2 \
217 origin "+refs/heads/*:refs/remotes/origin/*"
220 . "$TEST_DIRECTORY"/lib-httpd.sh
221 start_httpd
223 REPO="$HTTPD_DOCUMENT_ROOT_PATH/repo"
225 test_expect_success 'shallow fetches check connectivity before writing shallow file' '
226 rm -rf "$REPO" client &&
228 git init "$REPO" &&
229 test_commit -C "$REPO" one &&
230 test_commit -C "$REPO" two &&
231 test_commit -C "$REPO" three &&
233 git init client &&
235 # Use protocol v2 to ensure that shallow information is sent exactly
236 # once by the server, since we are planning to manipulate it.
237 git -C "$REPO" config protocol.version 2 &&
238 git -C client config protocol.version 2 &&
240 git -C client fetch --depth=2 "$HTTPD_URL/one_time_perl/repo" master:a_branch &&
242 # Craft a situation in which the server sends back an unshallow request
243 # with an empty packfile. This is done by refetching with a shorter
244 # depth (to ensure that the packfile is empty), and overwriting the
245 # shallow line in the response with the unshallow line we want.
246 printf "$(test_oid perl)" \
247 "$(git -C "$REPO" rev-parse HEAD)" \
248 "$(git -C "$REPO" rev-parse HEAD^)" \
249 >"$HTTPD_ROOT_PATH/one-time-perl" &&
250 test_must_fail env GIT_TEST_SIDEBAND_ALL=0 git -C client \
251 fetch --depth=1 "$HTTPD_URL/one_time_perl/repo" \
252 master:a_branch &&
254 # Ensure that the one-time-perl script was used.
255 ! test -e "$HTTPD_ROOT_PATH/one-time-perl" &&
257 # Ensure that the resulting repo is consistent, despite our failure to
258 # fetch.
259 git -C client fsck
262 # DO NOT add non-httpd-specific tests here, because the last part of this
263 # test script is only executed when httpd is available and enabled.
265 test_done