1#!/bin/sh
23
test_description='fetch/clone from a shallow clone'
45
. ./test-lib.sh
67
commit() {
8echo "$1" >tracked &&
9git add tracked &&
10git commit -m "$1"
11}
1213
test_expect_success 'setup' '
14commit 1 &&
15commit 2 &&
16commit 3 &&
17commit 4 &&
18git config --global transfer.fsckObjects true
19'
2021
test_expect_success 'setup shallow clone' '
22git clone --no-local --depth=2 .git shallow &&
23git --git-dir=shallow/.git log --format=%s >actual &&
24cat <<EOF >expect &&
254
263
27EOF
28test_cmp expect actual
29'
3031
test_expect_success 'clone from shallow clone' '
32git clone --no-local shallow shallow2 &&
33(
34cd shallow2 &&
35git fsck &&
36git log --format=%s >actual &&
37cat <<EOF >expect &&
384
393
40EOF
41test_cmp expect actual
42)
43'
4445
test_expect_success 'fetch from shallow clone' '
46(
47cd shallow &&
48commit 5
49) &&
50(
51cd shallow2 &&
52git fetch &&
53git fsck &&
54git log --format=%s origin/master >actual &&
55cat <<EOF >expect &&
565
574
583
59EOF
60test_cmp expect actual
61)
62'
6364
test_expect_success 'fetch --depth from shallow clone' '
65(
66cd shallow &&
67commit 6
68) &&
69(
70cd shallow2 &&
71git fetch --depth=2 &&
72git fsck &&
73git log --format=%s origin/master >actual &&
74cat <<EOF >expect &&
756
765
77EOF
78test_cmp expect actual
79)
80'
8182
test_expect_success 'fetch something upstream has but hidden by clients shallow boundaries' '
83# the blob "1" is available in .git but hidden by the
84# shallow2/.git/shallow and it should be resent
85! git --git-dir=shallow2/.git cat-file blob `echo 1|git hash-object --stdin` >/dev/null &&
86echo 1 >1.t &&
87git add 1.t &&
88git commit -m add-1-back &&
89(
90cd shallow2 &&
91git fetch ../.git +refs/heads/master:refs/remotes/top/master &&
92git fsck &&
93git log --format=%s top/master >actual &&
94cat <<EOF >expect &&
95add-1-back
964
973
98EOF
99test_cmp expect actual
100) &&
101git --git-dir=shallow2/.git cat-file blob `echo 1|git hash-object --stdin` >/dev/null
102103
'
104105
test_expect_success 'fetch that requires changes in .git/shallow is filtered' '
106(
107cd shallow &&
108git checkout --orphan no-shallow &&
109commit no-shallow
110) &&
111git init notshallow &&
112(
113cd notshallow &&
114git fetch ../shallow/.git refs/heads/*:refs/remotes/shallow/*&&
115git for-each-ref --format="%(refname)" >actual.refs &&
116cat <<EOF >expect.refs &&
117refs/remotes/shallow/no-shallow
118EOF
119test_cmp expect.refs actual.refs &&
120git log --format=%s shallow/no-shallow >actual &&
121cat <<EOF >expect &&
122no-shallow
123EOF
124test_cmp expect actual
125)
126'
127128
test_done