1#!/bin/sh
23
test_description='Test shallow cloning of repos with submodules'
45
. ./test-lib.sh
67
pwd=$(pwd)
89
test_expect_success 'setup' '
10git checkout -b master &&
11test_commit commit1 &&
12test_commit commit2 &&
13mkdir sub &&
14(
15cd sub &&
16git init &&
17test_commit subcommit1 &&
18test_commit subcommit2 &&
19test_commit subcommit3
20) &&
21git submodule add "file://$pwd/sub" sub &&
22git commit -m "add submodule"
23'
2425
test_expect_success 'nonshallow clone implies nonshallow submodule' '
26test_when_finished "rm -rf super_clone" &&
27git clone --recurse-submodules "file://$pwd/." super_clone &&
28(
29cd super_clone &&
30git log --oneline >lines &&
31test_line_count = 3 lines
32) &&
33(
34cd super_clone/sub &&
35git log --oneline >lines &&
36test_line_count = 3 lines
37)
38'
3940
test_expect_success 'shallow clone implies shallow submodule' '
41test_when_finished "rm -rf super_clone" &&
42git clone --recurse-submodules --depth 2 "file://$pwd/." super_clone &&
43(
44cd super_clone &&
45git log --oneline >lines &&
46test_line_count = 2 lines
47) &&
48(
49cd super_clone/sub &&
50git log --oneline >lines &&
51test_line_count = 1 lines
52)
53'
5455
test_expect_success 'shallow clone with non shallow submodule' '
56test_when_finished "rm -rf super_clone" &&
57git clone --recurse-submodules --depth 2 --no-shallow-submodules "file://$pwd/." super_clone &&
58(
59cd super_clone &&
60git log --oneline >lines &&
61test_line_count = 2 lines
62) &&
63(
64cd super_clone/sub &&
65git log --oneline >lines &&
66test_line_count = 3 lines
67)
68'
6970
test_expect_success 'non shallow clone with shallow submodule' '
71test_when_finished "rm -rf super_clone" &&
72git clone --recurse-submodules --no-local --shallow-submodules "file://$pwd/." super_clone &&
73(
74cd super_clone &&
75git log --oneline >lines &&
76test_line_count = 3 lines
77) &&
78(
79cd super_clone/sub &&
80git log --oneline >lines &&
81test_line_count = 1 lines
82)
83'
8485
test_expect_success 'clone follows shallow recommendation' '
86test_when_finished "rm -rf super_clone" &&
87git config -f .gitmodules submodule.sub.shallow true &&
88git add .gitmodules &&
89git commit -m "recommed shallow for sub" &&
90git clone --recurse-submodules --no-local "file://$pwd/." super_clone &&
91(
92cd super_clone &&
93git log --oneline >lines &&
94test_line_count = 4 lines
95) &&
96(
97cd super_clone/sub &&
98git log --oneline >lines &&
99test_line_count = 1 lines
100)
101'
102103
test_expect_success 'get unshallow recommended shallow submodule' '
104test_when_finished "rm -rf super_clone" &&
105git clone --no-local "file://$pwd/." super_clone &&
106(
107cd super_clone &&
108git submodule update --init --no-recommend-shallow &&
109git log --oneline >lines &&
110test_line_count = 4 lines
111) &&
112(
113cd super_clone/sub &&
114git log --oneline >lines &&
115test_line_count = 3 lines
116)
117'
118119
test_expect_success 'clone follows non shallow recommendation' '
120test_when_finished "rm -rf super_clone" &&
121git config -f .gitmodules submodule.sub.shallow false &&
122git add .gitmodules &&
123git commit -m "recommed non shallow for sub" &&
124git clone --recurse-submodules --no-local "file://$pwd/." super_clone &&
125(
126cd super_clone &&
127git log --oneline >lines &&
128test_line_count = 5 lines
129) &&
130(
131cd super_clone/sub &&
132git log --oneline >lines &&
133test_line_count = 3 lines
134)
135'
136137
test_done