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 something upstream has but hidden by clients shallow boundaries' '
85 # the blob "1" is available in .git but hidden by the
86 # shallow2/.git/shallow and it should be resent
87 ! git --git-dir=shallow2/.git cat-file blob $(echo 1|git hash-object --stdin) >/dev/null &&
90 git commit -m add-1-back &&
93 git fetch ../.git +refs/heads/master:refs/remotes/top/master &&
95 git log --format=%s top/master >actual &&
96 test_write_lines add-1-back 4 3 >expect &&
97 test_cmp expect actual
99 git --git-dir=shallow2/.git cat-file blob $(echo 1|git hash-object --stdin) >/dev/null
102 test_expect_success 'fetch that requires changes in .git/shallow is filtered' '
105 git checkout --orphan no-shallow &&
108 git init notshallow &&
111 git fetch ../shallow/.git refs/heads/*:refs/remotes/shallow/* &&
112 git for-each-ref --format="%(refname)" >actual.refs &&
113 echo refs/remotes/shallow/no-shallow >expect.refs &&
114 test_cmp expect.refs actual.refs &&
115 git log --format=%s shallow/no-shallow >actual &&
116 echo no-shallow >expect &&
117 test_cmp expect actual
121 test_expect_success 'fetch --update-shallow' '
124 git checkout master &&
126 git tag -m foo heavy-tag HEAD^ &&
127 git tag light-tag HEAD^:tracked
131 git fetch --update-shallow ../shallow/.git refs/heads/*:refs/remotes/shallow/* &&
133 git for-each-ref --sort=refname --format="%(refname)" >actual.refs &&
134 cat <<-\EOF >expect.refs &&
135 refs/remotes/shallow/master
136 refs/remotes/shallow/no-shallow
140 test_cmp expect.refs actual.refs &&
141 git log --format=%s shallow/master >actual &&
142 test_write_lines 7 6 5 4 3 >expect &&
143 test_cmp expect actual
147 test_expect_success 'fetch --update-shallow (with fetch.writeCommitGraph)' '
150 git checkout master &&
152 git tag -m foo heavy-tag-for-graph HEAD^ &&
153 git tag light-tag-for-graph HEAD^:tracked
155 test_config -C notshallow fetch.writeCommitGraph true &&
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
165 refs/tags/heavy-tag-for-graph
167 refs/tags/light-tag-for-graph
169 test_cmp expect.refs actual.refs &&
170 git log --format=%s shallow/master >actual &&
171 test_write_lines 8 7 6 5 4 3 >expect &&
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 &&
182 test_write_lines add-1-back 4 >expect &&
183 test_cmp expect actual
186 test_expect_success '.git/shallow is edited by repack' '
187 git init shallow-server &&
188 test_commit -C shallow-server A &&
189 test_commit -C shallow-server B &&
190 git -C shallow-server checkout -b branch &&
191 test_commit -C shallow-server C &&
192 test_commit -C shallow-server E &&
193 test_commit -C shallow-server D &&
194 d="$(git -C shallow-server rev-parse --verify D^0)" &&
195 git -C shallow-server checkout master &&
197 git clone --depth=1 --no-tags --no-single-branch \
198 "file://$PWD/shallow-server" shallow-client &&
200 : now remove the branch and fetch with prune &&
201 git -C shallow-server branch -D branch &&
202 git -C shallow-client fetch --prune --depth=1 \
203 origin "+refs/heads/*:refs/remotes/origin/*" &&
204 git -C shallow-client repack -adfl &&
205 test_must_fail git -C shallow-client rev-parse --verify $d^0 &&
206 ! grep $d shallow-client/.git/shallow &&
208 git -C shallow-server branch branch-orig $d &&
209 git -C shallow-client fetch --prune --depth=2 \
210 origin "+refs/heads/*:refs/remotes/origin/*"
213 . "$TEST_DIRECTORY"/lib-httpd.sh
216 REPO="$HTTPD_DOCUMENT_ROOT_PATH/repo"
218 test_expect_success 'shallow fetches check connectivity before writing shallow file' '
219 rm -rf "$REPO" client &&
222 test_commit -C "$REPO" one &&
223 test_commit -C "$REPO" two &&
224 test_commit -C "$REPO" three &&
228 # Use protocol v2 to ensure that shallow information is sent exactly
229 # once by the server, since we are planning to manipulate it.
230 git -C "$REPO" config protocol.version 2 &&
231 git -C client config protocol.version 2 &&
233 git -C client fetch --depth=2 "$HTTPD_URL/one_time_perl/repo" master:a_branch &&
235 # Craft a situation in which the server sends back an unshallow request
236 # with an empty packfile. This is done by refetching with a shorter
237 # depth (to ensure that the packfile is empty), and overwriting the
238 # shallow line in the response with the unshallow line we want.
239 printf "$(test_oid perl)" \
240 "$(git -C "$REPO" rev-parse HEAD)" \
241 "$(git -C "$REPO" rev-parse HEAD^)" \
242 >"$HTTPD_ROOT_PATH/one-time-perl" &&
243 test_must_fail env GIT_TEST_SIDEBAND_ALL=0 git -C client \
244 fetch --depth=1 "$HTTPD_URL/one_time_perl/repo" \
247 # Ensure that the one-time-perl script was used.
248 ! test -e "$HTTPD_ROOT_PATH/one-time-perl" &&
250 # Ensure that the resulting repo is consistent, despite our failure to
255 # DO NOT add non-httpd-specific tests here, because the last part of this
256 # test script is only executed when httpd is available and enabled.