3 test_description
='Test shallow cloning of repos with submodules'
9 test_expect_success
'setup' '
10 git checkout -b main &&
11 test_commit commit1 &&
12 test_commit commit2 &&
17 test_commit subcommit1 &&
18 test_commit subcommit2 &&
19 test_commit subcommit3
21 git submodule add "file://$pwd/sub" sub &&
22 git commit -m "add submodule"
25 test_expect_success
'nonshallow clone implies nonshallow submodule' '
26 test_when_finished "rm -rf super_clone" &&
27 test_config_global protocol.file.allow always &&
28 git clone --recurse-submodules "file://$pwd/." super_clone &&
29 git -C super_clone log --oneline >lines &&
30 test_line_count = 3 lines &&
31 git -C super_clone/sub log --oneline >lines &&
32 test_line_count = 3 lines
35 test_expect_success
'shallow clone with shallow submodule' '
36 test_when_finished "rm -rf super_clone" &&
37 test_config_global protocol.file.allow always &&
38 git clone --recurse-submodules --depth 2 --shallow-submodules "file://$pwd/." super_clone &&
39 git -C super_clone log --oneline >lines &&
40 test_line_count = 2 lines &&
41 git -C super_clone/sub log --oneline >lines &&
42 test_line_count = 1 lines
45 test_expect_success
'shallow clone does not imply shallow submodule' '
46 test_when_finished "rm -rf super_clone" &&
47 test_config_global protocol.file.allow always &&
48 git clone --recurse-submodules --depth 2 "file://$pwd/." super_clone &&
49 git -C super_clone log --oneline >lines &&
50 test_line_count = 2 lines &&
51 git -C super_clone/sub log --oneline >lines &&
52 test_line_count = 3 lines
55 test_expect_success
'shallow clone with non shallow submodule' '
56 test_when_finished "rm -rf super_clone" &&
57 test_config_global protocol.file.allow always &&
58 git clone --recurse-submodules --depth 2 --no-shallow-submodules "file://$pwd/." super_clone &&
59 git -C super_clone log --oneline >lines &&
60 test_line_count = 2 lines &&
61 git -C super_clone/sub log --oneline >lines &&
62 test_line_count = 3 lines
65 test_expect_success
'non shallow clone with shallow submodule' '
66 test_when_finished "rm -rf super_clone" &&
67 test_config_global protocol.file.allow always &&
68 git clone --recurse-submodules --no-local --shallow-submodules "file://$pwd/." super_clone &&
69 git -C super_clone log --oneline >lines &&
70 test_line_count = 3 lines &&
71 git -C super_clone/sub log --oneline >lines &&
72 test_line_count = 1 lines
75 test_expect_success
'clone follows shallow recommendation' '
76 test_when_finished "rm -rf super_clone" &&
77 test_config_global protocol.file.allow always &&
78 git config -f .gitmodules submodule.sub.shallow true &&
79 git add .gitmodules &&
80 git commit -m "recommend shallow for sub" &&
81 git clone --recurse-submodules --no-local "file://$pwd/." super_clone &&
84 git log --oneline >lines &&
85 test_line_count = 4 lines
89 git log --oneline >lines &&
90 test_line_count = 1 lines
94 test_expect_success
'get unshallow recommended shallow submodule' '
95 test_when_finished "rm -rf super_clone" &&
96 test_config_global protocol.file.allow always &&
97 git clone --no-local "file://$pwd/." super_clone &&
100 git submodule update --init --no-recommend-shallow &&
101 git log --oneline >lines &&
102 test_line_count = 4 lines
105 cd super_clone/sub &&
106 git log --oneline >lines &&
107 test_line_count = 3 lines
111 test_expect_success
'clone follows non shallow recommendation' '
112 test_when_finished "rm -rf super_clone" &&
113 test_config_global protocol.file.allow always &&
114 git config -f .gitmodules submodule.sub.shallow false &&
115 git add .gitmodules &&
116 git commit -m "recommend non shallow for sub" &&
117 git clone --recurse-submodules --no-local "file://$pwd/." super_clone &&
120 git log --oneline >lines &&
121 test_line_count = 5 lines
124 cd super_clone/sub &&
125 git log --oneline >lines &&
126 test_line_count = 3 lines