]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5614-clone-submodules-shallow.sh
The third batch
[thirdparty/git.git] / t / t5614-clone-submodules-shallow.sh
CommitLineData
d22eb044
SB
1#!/bin/sh
2
3test_description='Test shallow cloning of repos with submodules'
4
dd4143e7 5TEST_PASSES_SANITIZE_LEAK=true
d22eb044
SB
6. ./test-lib.sh
7
8pwd=$(pwd)
9
10test_expect_success 'setup' '
95cf2c01 11 git checkout -b main &&
d22eb044
SB
12 test_commit commit1 &&
13 test_commit commit2 &&
14 mkdir sub &&
15 (
16 cd sub &&
17 git init &&
18 test_commit subcommit1 &&
19 test_commit subcommit2 &&
20 test_commit subcommit3
21 ) &&
22 git submodule add "file://$pwd/sub" sub &&
23 git commit -m "add submodule"
24'
25
26test_expect_success 'nonshallow clone implies nonshallow submodule' '
27 test_when_finished "rm -rf super_clone" &&
225d2d50 28 test_config_global protocol.file.allow always &&
d22eb044 29 git clone --recurse-submodules "file://$pwd/." super_clone &&
5819c2ee
SB
30 git -C super_clone log --oneline >lines &&
31 test_line_count = 3 lines &&
32 git -C super_clone/sub log --oneline >lines &&
33 test_line_count = 3 lines
d22eb044
SB
34'
35
18a74a09 36test_expect_success 'shallow clone with shallow submodule' '
d22eb044 37 test_when_finished "rm -rf super_clone" &&
225d2d50 38 test_config_global protocol.file.allow always &&
18a74a09 39 git clone --recurse-submodules --depth 2 --shallow-submodules "file://$pwd/." super_clone &&
5819c2ee
SB
40 git -C super_clone log --oneline >lines &&
41 test_line_count = 2 lines &&
42 git -C super_clone/sub log --oneline >lines &&
43 test_line_count = 1 lines
d22eb044
SB
44'
45
18a74a09
JH
46test_expect_success 'shallow clone does not imply shallow submodule' '
47 test_when_finished "rm -rf super_clone" &&
225d2d50 48 test_config_global protocol.file.allow always &&
18a74a09 49 git clone --recurse-submodules --depth 2 "file://$pwd/." super_clone &&
5819c2ee
SB
50 git -C super_clone log --oneline >lines &&
51 test_line_count = 2 lines &&
52 git -C super_clone/sub log --oneline >lines &&
53 test_line_count = 3 lines
18a74a09
JH
54'
55
d22eb044
SB
56test_expect_success 'shallow clone with non shallow submodule' '
57 test_when_finished "rm -rf super_clone" &&
225d2d50 58 test_config_global protocol.file.allow always &&
d22eb044 59 git clone --recurse-submodules --depth 2 --no-shallow-submodules "file://$pwd/." super_clone &&
5819c2ee
SB
60 git -C super_clone log --oneline >lines &&
61 test_line_count = 2 lines &&
62 git -C super_clone/sub log --oneline >lines &&
63 test_line_count = 3 lines
d22eb044
SB
64'
65
66test_expect_success 'non shallow clone with shallow submodule' '
67 test_when_finished "rm -rf super_clone" &&
225d2d50 68 test_config_global protocol.file.allow always &&
d22eb044 69 git clone --recurse-submodules --no-local --shallow-submodules "file://$pwd/." super_clone &&
5819c2ee
SB
70 git -C super_clone log --oneline >lines &&
71 test_line_count = 3 lines &&
72 git -C super_clone/sub log --oneline >lines &&
73 test_line_count = 1 lines
d22eb044
SB
74'
75
abed000a
SB
76test_expect_success 'clone follows shallow recommendation' '
77 test_when_finished "rm -rf super_clone" &&
225d2d50 78 test_config_global protocol.file.allow always &&
abed000a
SB
79 git config -f .gitmodules submodule.sub.shallow true &&
80 git add .gitmodules &&
64127575 81 git commit -m "recommend shallow for sub" &&
abed000a
SB
82 git clone --recurse-submodules --no-local "file://$pwd/." super_clone &&
83 (
84 cd super_clone &&
85 git log --oneline >lines &&
86 test_line_count = 4 lines
87 ) &&
88 (
89 cd super_clone/sub &&
90 git log --oneline >lines &&
91 test_line_count = 1 lines
92 )
93'
94
95test_expect_success 'get unshallow recommended shallow submodule' '
96 test_when_finished "rm -rf super_clone" &&
225d2d50 97 test_config_global protocol.file.allow always &&
abed000a
SB
98 git clone --no-local "file://$pwd/." super_clone &&
99 (
100 cd super_clone &&
101 git submodule update --init --no-recommend-shallow &&
102 git log --oneline >lines &&
103 test_line_count = 4 lines
104 ) &&
105 (
106 cd super_clone/sub &&
107 git log --oneline >lines &&
108 test_line_count = 3 lines
109 )
110'
111
112test_expect_success 'clone follows non shallow recommendation' '
113 test_when_finished "rm -rf super_clone" &&
225d2d50 114 test_config_global protocol.file.allow always &&
abed000a
SB
115 git config -f .gitmodules submodule.sub.shallow false &&
116 git add .gitmodules &&
64127575 117 git commit -m "recommend non shallow for sub" &&
abed000a
SB
118 git clone --recurse-submodules --no-local "file://$pwd/." super_clone &&
119 (
120 cd super_clone &&
121 git log --oneline >lines &&
122 test_line_count = 5 lines
123 ) &&
124 (
125 cd super_clone/sub &&
126 git log --oneline >lines &&
127 test_line_count = 3 lines
128 )
129'
130
d22eb044 131test_done