1#!/bin/sh
23
test_description='push from/to 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' '
14git config --global transfer.fsckObjects true &&
15commit 1 &&
16commit 2 &&
17commit 3 &&
18commit 4 &&
19git clone . full &&
20(
21git init full-abc &&
22cd full-abc &&
23commit a &&
24commit b &&
25commit c
26) &&
27git clone --no-local --depth=2 .git shallow &&
28git --git-dir=shallow/.git log --format=%s >actual &&
29cat <<EOF >expect &&
304
313
32EOF
33test_cmp expect actual &&
34git clone --no-local --depth=2 full-abc/.git shallow2 &&
35git --git-dir=shallow2/.git log --format=%s >actual &&
36cat <<EOF >expect &&
37c
38b
39EOF
40test_cmp expect actual
41'
4243
test_expect_success 'push from shallow clone' '
44(
45cd shallow &&
46commit 5 &&
47git push ../.git +master:refs/remotes/shallow/master
48) &&
49git log --format=%s shallow/master >actual &&
50git fsck &&
51cat <<EOF >expect &&
525
534
543
552
561
57EOF
58test_cmp expect actual
59'
6061
test_expect_success 'push from shallow clone, with grafted roots' '
62(
63cd shallow2 &&
64test_must_fail git push ../.git +master:refs/remotes/shallow2/master 2>err &&
65grep "shallow2/master.*shallow update not allowed" err
66) &&
67test_must_fail git rev-parse shallow2/master &&
68git fsck
69'
7071
test_expect_success 'add new shallow root with receive.updateshallow on' '
72test_config receive.shallowupdate true &&
73(
74cd shallow2 &&
75git push ../.git +master:refs/remotes/shallow2/master
76) &&
77git log --format=%s shallow2/master >actual &&
78git fsck &&
79cat <<EOF >expect &&
80c
81b
82EOF
83test_cmp expect actual
84'
8586
test_expect_success 'push from shallow to shallow' '
87(
88cd shallow &&
89git --git-dir=../shallow2/.git config receive.shallowupdate true &&
90git push ../shallow2/.git +master:refs/remotes/shallow/master &&
91git --git-dir=../shallow2/.git config receive.shallowupdate false
92) &&
93(
94cd shallow2 &&
95git log --format=%s shallow/master >actual &&
96git fsck &&
97cat <<EOF >expect &&
985
994
1003
101EOF
102test_cmp expect actual
103)
104'
105106
test_expect_success 'push from full to shallow' '
107! git --git-dir=shallow2/.git cat-file blob $(echo 1|git hash-object --stdin) &&
108commit 1 &&
109git push shallow2/.git +master:refs/remotes/top/master &&
110(
111cd shallow2 &&
112git log --format=%s top/master >actual &&
113git fsck &&
114cat <<EOF >expect &&
1151
1164
1173
118EOF
119test_cmp expect actual &&
120git cat-file blob $(echo 1|git hash-object --stdin) >/dev/null
121)
122'
123test_done