3 test_description
='fetch/clone from a shallow clone'
13 test_expect_success
'setup' '
18 git config --global transfer.fsckObjects true
21 test_expect_success
'setup shallow clone' '
22 git clone --no-local --depth=2 .git shallow &&
23 git --git-dir=shallow/.git log --format=%s >actual &&
28 test_cmp expect actual
31 test_expect_success
'clone from shallow clone' '
32 git clone --no-local shallow shallow2 &&
36 git log --format=%s >actual &&
41 test_cmp expect actual
45 test_expect_success
'fetch from shallow clone' '
54 git log --format=%s origin/master >actual &&
60 test_cmp expect actual
64 test_expect_success
'fetch --depth from shallow clone' '
71 git fetch --depth=2 &&
73 git log --format=%s origin/master >actual &&
78 test_cmp expect actual
82 test_expect_success
'fetch --unshallow from shallow clone' '
85 git fetch --unshallow &&
87 git log --format=%s origin/master >actual &&
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 &&
115 test_cmp expect actual
117 git --git-dir=shallow2/.git cat-file blob $(echo 1|git hash-object --stdin) >/dev/null
121 test_expect_success
'fetch that requires changes in .git/shallow is filtered' '
124 git checkout --orphan no-shallow &&
127 git init notshallow &&
130 git fetch ../shallow/.git refs/heads/*:refs/remotes/shallow/*&&
131 git for-each-ref --format="%(refname)" >actual.refs &&
132 cat <<EOF >expect.refs &&
133 refs/remotes/shallow/no-shallow
135 test_cmp expect.refs actual.refs &&
136 git log --format=%s shallow/no-shallow >actual &&
140 test_cmp expect actual
144 test_expect_success
'fetch --update-shallow' '
147 git checkout master &&
149 git tag -m foo heavy-tag HEAD^ &&
150 git tag light-tag HEAD^:tracked
154 git fetch --update-shallow ../shallow/.git refs/heads/*:refs/remotes/shallow/* &&
156 git for-each-ref --sort=refname --format="%(refname)" >actual.refs &&
157 cat <<EOF >expect.refs &&
158 refs/remotes/shallow/master
159 refs/remotes/shallow/no-shallow
163 test_cmp expect.refs actual.refs &&
164 git log --format=%s shallow/master >actual &&
172 test_cmp expect actual
176 test_expect_success POSIXPERM
,SANITY
'shallow fetch from a read-only repo' '
177 cp -R .git read-only.git &&
178 test_when_finished "find read-only.git -type d -print | xargs chmod +w" &&
179 find read-only.git -print | xargs chmod -w &&
180 git clone --no-local --depth=2 read-only.git from-read-only &&
181 git --git-dir=from-read-only/.git log --format=%s >actual &&
186 test_cmp expect actual
189 .
"$TEST_DIRECTORY"/lib-httpd.sh
192 REPO
="$HTTPD_DOCUMENT_ROOT_PATH/repo"
194 test_expect_success
'shallow fetches check connectivity before writing shallow file' '
195 rm -rf "$REPO" client &&
198 test_commit -C "$REPO" one &&
199 test_commit -C "$REPO" two &&
200 test_commit -C "$REPO" three &&
204 # Use protocol v2 to ensure that shallow information is sent exactly
205 # once by the server, since we are planning to manipulate it.
206 git -C "$REPO" config protocol.version 2 &&
207 git -C client config protocol.version 2 &&
209 git -C client fetch --depth=2 "$HTTPD_URL/one_time_sed/repo" master:a_branch &&
211 # Craft a situation in which the server sends back an unshallow request
212 # with an empty packfile. This is done by refetching with a shorter
213 # depth (to ensure that the packfile is empty), and overwriting the
214 # shallow line in the response with the unshallow line we want.
215 printf "s/0034shallow %s/0036unshallow %s/" \
216 "$(git -C "$REPO" rev-parse HEAD)" \
217 "$(git -C "$REPO" rev-parse HEAD^)" \
218 >"$HTTPD_ROOT_PATH/one-time-sed" &&
219 test_must_fail git -C client fetch --depth=1 "$HTTPD_URL/one_time_sed/repo" \
222 # Ensure that the one-time-sed script was used.
223 ! test -e "$HTTPD_ROOT_PATH/one-time-sed" &&
225 # Ensure that the resulting repo is consistent, despite our failure to