Merge branch 'ak/t7800-wo-readlink'
[git] / t / t5614-clone-submodules.sh
1 #!/bin/sh
2
3 test_description='Test shallow cloning of repos with submodules'
4
5 . ./test-lib.sh
6
7 pwd=$(pwd)
8
9 test_expect_success 'setup' '
10         git checkout -b master &&
11         test_commit commit1 &&
12         test_commit commit2 &&
13         mkdir sub &&
14         (
15                 cd sub &&
16                 git init &&
17                 test_commit subcommit1 &&
18                 test_commit subcommit2 &&
19                 test_commit subcommit3
20         ) &&
21         git submodule add "file://$pwd/sub" sub &&
22         git commit -m "add submodule"
23 '
24
25 test_expect_success 'nonshallow clone implies nonshallow submodule' '
26         test_when_finished "rm -rf super_clone" &&
27         git clone --recurse-submodules "file://$pwd/." super_clone &&
28         (
29                 cd super_clone &&
30                 git log --oneline >lines &&
31                 test_line_count = 3 lines
32         ) &&
33         (
34                 cd super_clone/sub &&
35                 git log --oneline >lines &&
36                 test_line_count = 3 lines
37         )
38 '
39
40 test_expect_success 'shallow clone with shallow submodule' '
41         test_when_finished "rm -rf super_clone" &&
42         git clone --recurse-submodules --depth 2 --shallow-submodules "file://$pwd/." super_clone &&
43         (
44                 cd super_clone &&
45                 git log --oneline >lines &&
46                 test_line_count = 2 lines
47         ) &&
48         (
49                 cd super_clone/sub &&
50                 git log --oneline >lines &&
51                 test_line_count = 1 lines
52         )
53 '
54
55 test_expect_success 'shallow clone does not imply shallow submodule' '
56         test_when_finished "rm -rf super_clone" &&
57         git clone --recurse-submodules --depth 2 "file://$pwd/." super_clone &&
58         (
59                 cd super_clone &&
60                 git log --oneline >lines &&
61                 test_line_count = 2 lines
62         ) &&
63         (
64                 cd super_clone/sub &&
65                 git log --oneline >lines &&
66                 test_line_count = 3 lines
67         )
68 '
69
70 test_expect_success 'shallow clone with non shallow submodule' '
71         test_when_finished "rm -rf super_clone" &&
72         git clone --recurse-submodules --depth 2 --no-shallow-submodules "file://$pwd/." super_clone &&
73         (
74                 cd super_clone &&
75                 git log --oneline >lines &&
76                 test_line_count = 2 lines
77         ) &&
78         (
79                 cd super_clone/sub &&
80                 git log --oneline >lines &&
81                 test_line_count = 3 lines
82         )
83 '
84
85 test_expect_success 'non shallow clone with shallow submodule' '
86         test_when_finished "rm -rf super_clone" &&
87         git clone --recurse-submodules --no-local --shallow-submodules "file://$pwd/." super_clone &&
88         (
89                 cd super_clone &&
90                 git log --oneline >lines &&
91                 test_line_count = 3 lines
92         ) &&
93         (
94                 cd super_clone/sub &&
95                 git log --oneline >lines &&
96                 test_line_count = 1 lines
97         )
98 '
99
100 test_expect_success 'clone follows shallow recommendation' '
101         test_when_finished "rm -rf super_clone" &&
102         git config -f .gitmodules submodule.sub.shallow true &&
103         git add .gitmodules &&
104         git commit -m "recommed shallow for sub" &&
105         git clone --recurse-submodules --no-local "file://$pwd/." super_clone &&
106         (
107                 cd super_clone &&
108                 git log --oneline >lines &&
109                 test_line_count = 4 lines
110         ) &&
111         (
112                 cd super_clone/sub &&
113                 git log --oneline >lines &&
114                 test_line_count = 1 lines
115         )
116 '
117
118 test_expect_success 'get unshallow recommended shallow submodule' '
119         test_when_finished "rm -rf super_clone" &&
120         git clone --no-local "file://$pwd/." super_clone &&
121         (
122                 cd super_clone &&
123                 git submodule update --init --no-recommend-shallow &&
124                 git log --oneline >lines &&
125                 test_line_count = 4 lines
126         ) &&
127         (
128                 cd super_clone/sub &&
129                 git log --oneline >lines &&
130                 test_line_count = 3 lines
131         )
132 '
133
134 test_expect_success 'clone follows non shallow recommendation' '
135         test_when_finished "rm -rf super_clone" &&
136         git config -f .gitmodules submodule.sub.shallow false &&
137         git add .gitmodules &&
138         git commit -m "recommed non shallow for sub" &&
139         git clone --recurse-submodules --no-local "file://$pwd/." super_clone &&
140         (
141                 cd super_clone &&
142                 git log --oneline >lines &&
143                 test_line_count = 5 lines
144         ) &&
145         (
146                 cd super_clone/sub &&
147                 git log --oneline >lines &&
148                 test_line_count = 3 lines
149         )
150 '
151
152 test_done