3 test_description
='fetch/clone from a shallow clone'
13 test_expect_success
'setup' '
18 git config --global transfer.fsckObjects true &&
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 &&
32 test_cmp expect actual
35 test_expect_success
'clone from shallow clone' '
36 git clone --no-local shallow shallow2 &&
40 git log --format=%s >actual &&
45 test_cmp expect actual
49 test_expect_success
'fetch from shallow clone' '
58 git log --format=%s origin/master >actual &&
64 test_cmp expect actual
68 test_expect_success
'fetch --depth from shallow clone' '
75 git fetch --depth=2 &&
77 git log --format=%s origin/master >actual &&
82 test_cmp expect actual
86 test_expect_success
'fetch --unshallow from shallow clone' '
89 git fetch --unshallow &&
91 git log --format=%s origin/master >actual &&
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 &&
108 git commit -m add-1-back &&
111 git fetch ../.git +refs/heads/master:refs/remotes/top/master &&
113 git log --format=%s top/master >actual &&
119 test_cmp expect actual
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' '
128 git checkout --orphan no-shallow &&
131 git init 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 &&
144 test_cmp expect actual
148 test_expect_success
'fetch --update-shallow' '
151 git checkout master &&
153 git tag -m foo heavy-tag HEAD^ &&
154 git tag light-tag HEAD^:tracked
158 git fetch --update-shallow ../shallow/.git refs/heads/*:refs/remotes/shallow/* &&
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
167 test_cmp expect.refs actual.refs &&
168 git log --format=%s shallow/master >actual &&
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 &&
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
223 REPO
="$HTTPD_DOCUMENT_ROOT_PATH/repo"
225 test_expect_success
'shallow fetches check connectivity before writing shallow file' '
226 rm -rf "$REPO" client &&
229 test_commit -C "$REPO" one &&
230 test_commit -C "$REPO" two &&
231 test_commit -C "$REPO" three &&
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" \
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
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.