3 test_description
='fetch/clone from a shallow clone'
13 test_expect_success
'setup' '
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/
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 test_write_lines 4 3 >expect &&
29 test_cmp expect actual
32 test_expect_success
'clone from shallow clone' '
33 git clone --no-local shallow shallow2 &&
37 git log --format=%s >actual &&
38 test_write_lines 4 3 >expect &&
39 test_cmp expect actual
43 test_expect_success
'fetch from shallow clone' '
52 git log --format=%s origin/master >actual &&
53 test_write_lines 5 4 3 >expect &&
54 test_cmp expect actual
58 test_expect_success
'fetch --depth from shallow clone' '
65 git fetch --depth=2 &&
67 git log --format=%s origin/master >actual &&
68 test_write_lines 6 5 >expect &&
69 test_cmp expect actual
73 test_expect_success
'fetch --unshallow from shallow clone' '
76 git fetch --unshallow &&
78 git log --format=%s origin/master >actual &&
79 test_write_lines 6 5 4 3 >expect &&
80 test_cmp expect actual
84 test_expect_success
'fetch --unshallow from a full clone' '
85 git clone --no-local --depth=2 .git 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
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
101 ! git --git-dir=shallow2/.git cat-file blob $(echo 1|git hash-object --stdin) >/dev/null &&
104 git commit -m add-1-back &&
107 git fetch ../.git +refs/heads/master:refs/remotes/top/master &&
109 git log --format=%s top/master >actual &&
110 test_write_lines add-1-back 4 3 >expect &&
111 test_cmp expect actual
113 git --git-dir=shallow2/.git cat-file blob $(echo 1|git hash-object --stdin) >/dev/null
116 test_expect_success
'fetch that requires changes in .git/shallow is filtered' '
119 git checkout --orphan no-shallow &&
122 git init notshallow &&
125 git fetch ../shallow/.git refs/heads/*:refs/remotes/shallow/* &&
126 git for-each-ref --format="%(refname)" >actual.refs &&
127 echo refs/remotes/shallow/no-shallow >expect.refs &&
128 test_cmp expect.refs actual.refs &&
129 git log --format=%s shallow/no-shallow >actual &&
130 echo no-shallow >expect &&
131 test_cmp expect actual
135 test_expect_success
'fetch --update-shallow' '
138 git checkout master &&
140 git tag -m foo heavy-tag HEAD^ &&
141 git tag light-tag HEAD^:tracked
145 git fetch --update-shallow ../shallow/.git refs/heads/*:refs/remotes/shallow/* &&
147 git for-each-ref --sort=refname --format="%(refname)" >actual.refs &&
148 cat <<-\EOF >expect.refs &&
149 refs/remotes/shallow/master
150 refs/remotes/shallow/no-shallow
154 test_cmp expect.refs actual.refs &&
155 git log --format=%s shallow/master >actual &&
156 test_write_lines 7 6 5 4 3 >expect &&
157 test_cmp expect actual
161 test_expect_success
'fetch --update-shallow (with fetch.writeCommitGraph)' '
164 git checkout master &&
166 git tag -m foo heavy-tag-for-graph HEAD^ &&
167 git tag light-tag-for-graph HEAD^:tracked
169 test_config -C notshallow fetch.writeCommitGraph true &&
172 git fetch --update-shallow ../shallow/.git refs/heads/*:refs/remotes/shallow/* &&
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
179 refs/tags/heavy-tag-for-graph
181 refs/tags/light-tag-for-graph
183 test_cmp expect.refs actual.refs &&
184 git log --format=%s shallow/master >actual &&
185 test_write_lines 8 7 6 5 4 3 >expect &&
186 test_cmp expect actual
190 test_expect_success POSIXPERM
,SANITY
'shallow fetch from a read-only repo' '
191 cp -R .git read-only.git &&
192 test_when_finished "find read-only.git -type d -print | xargs chmod +w" &&
193 find read-only.git -print | xargs chmod -w &&
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 &&
196 test_write_lines add-1-back 4 >expect &&
197 test_cmp expect actual
200 test_expect_success
'.git/shallow is edited by repack' '
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 &&
211 git clone --depth=1 --no-tags --no-single-branch \
212 "file://$PWD/shallow-server" shallow-client &&
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 &&
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/*"
227 .
"$TEST_DIRECTORY"/lib-httpd.sh
230 REPO
="$HTTPD_DOCUMENT_ROOT_PATH/repo"
232 test_expect_success
'shallow fetches check connectivity before writing shallow file' '
233 rm -rf "$REPO" client &&
236 test_commit -C "$REPO" one &&
237 test_commit -C "$REPO" two &&
238 test_commit -C "$REPO" three &&
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 &&
247 git -C client fetch --depth=2 "$HTTPD_URL/one_time_perl/repo" master:a_branch &&
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.
253 printf "$(test_oid perl)" \
254 "$(git -C "$REPO" rev-parse HEAD)" \
255 "$(git -C "$REPO" rev-parse HEAD^)" \
256 >"$HTTPD_ROOT_PATH/one-time-perl" &&
257 test_must_fail env GIT_TEST_SIDEBAND_ALL=0 git -C client \
258 fetch --depth=1 "$HTTPD_URL/one_time_perl/repo" \
261 # Ensure that the one-time-perl script was used.
262 ! test -e "$HTTPD_ROOT_PATH/one-time-perl" &&
264 # Ensure that the resulting repo is consistent, despite our failure to
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.