Merge branch 'jc/run-command-use-embedded-args'
[git] / t / t7401-submodule-summary.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2008 Ping Yin
4 #
5
6 test_description='Summary support for submodules
7
8 This test script tries to verify the sanity of summary subcommand of git submodule.
9 '
10 # NEEDSWORK: This test script is old fashioned and may need a big cleanup due to
11 # various reasons, one of them being that there are lots of commands taking place
12 # outside of 'test_expect_success' block, which is no longer in good-style.
13
14 . ./test-lib.sh
15
16 add_file () {
17         sm=$1
18         shift
19         owd=$(pwd)
20         cd "$sm"
21         for name; do
22                 echo "$name" >"$name" &&
23                 git add "$name" &&
24                 test_tick &&
25                 git commit -m "Add $name"
26         done >/dev/null
27         git rev-parse --short HEAD
28         cd "$owd"
29 }
30 commit_file () {
31         test_tick &&
32         git commit "$@" -m "Commit $*" >/dev/null
33 }
34
35 test_create_repo sm1 &&
36 add_file . foo >/dev/null
37
38 head1=$(add_file sm1 foo1 foo2)
39
40 test_expect_success 'added submodule' "
41         git add sm1 &&
42         git submodule summary >actual &&
43         cat >expected <<-EOF &&
44         * sm1 0000000...$head1 (2):
45           > Add foo2
46
47         EOF
48         test_cmp expected actual
49 "
50
51 test_expect_success 'added submodule (subdirectory)' "
52         mkdir sub &&
53         (
54                 cd sub &&
55                 git submodule summary >../actual
56         ) &&
57         cat >expected <<-EOF &&
58         * ../sm1 0000000...$head1 (2):
59           > Add foo2
60
61         EOF
62         test_cmp expected actual
63 "
64
65 test_expect_success 'added submodule (subdirectory only)' "
66         (
67                 cd sub &&
68                 git submodule summary . >../actual
69         ) &&
70         test_must_be_empty actual
71 "
72
73 test_expect_success 'added submodule (subdirectory with explicit path)' "
74         (
75                 cd sub &&
76                 git submodule summary ../sm1 >../actual
77         ) &&
78         cat >expected <<-EOF &&
79         * ../sm1 0000000...$head1 (2):
80           > Add foo2
81
82         EOF
83         test_cmp expected actual
84 "
85
86 commit_file sm1 &&
87 head2=$(add_file sm1 foo3)
88
89 test_expect_success 'modified submodule(forward)' "
90         git submodule summary >actual &&
91         cat >expected <<-EOF &&
92         * sm1 $head1...$head2 (1):
93           > Add foo3
94
95         EOF
96         test_cmp expected actual
97 "
98
99 test_expect_success 'modified submodule(forward), --files' "
100         git submodule summary --files >actual &&
101         cat >expected <<-EOF &&
102         * sm1 $head1...$head2 (1):
103           > Add foo3
104
105         EOF
106         test_cmp expected actual
107 "
108
109 test_expect_success 'no ignore=all setting has any effect' "
110         git config -f .gitmodules submodule.sm1.path sm1 &&
111         git config -f .gitmodules submodule.sm1.ignore all &&
112         git config submodule.sm1.ignore all &&
113         git config diff.ignoreSubmodules all &&
114         git submodule summary >actual &&
115         cat >expected <<-EOF &&
116         * sm1 $head1...$head2 (1):
117           > Add foo3
118
119         EOF
120         test_cmp expected actual &&
121         git config --unset diff.ignoreSubmodules &&
122         git config --remove-section submodule.sm1 &&
123         git config -f .gitmodules --remove-section submodule.sm1
124 "
125
126
127 commit_file sm1 &&
128 head3=$(
129         cd sm1 &&
130         git reset --hard HEAD~2 >/dev/null &&
131         git rev-parse --short HEAD
132 )
133
134 test_expect_success 'modified submodule(backward)' "
135         git submodule summary >actual &&
136         cat >expected <<-EOF &&
137         * sm1 $head2...$head3 (2):
138           < Add foo3
139           < Add foo2
140
141         EOF
142         test_cmp expected actual
143 "
144
145 head4=$(add_file sm1 foo4 foo5) &&
146 head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD)
147 test_expect_success 'modified submodule(backward and forward)' "
148         git submodule summary >actual &&
149         cat >expected <<-EOF &&
150         * sm1 $head2...$head4 (4):
151           > Add foo5
152           > Add foo4
153           < Add foo3
154           < Add foo2
155
156         EOF
157         test_cmp expected actual
158 "
159
160 test_expect_success '--summary-limit' "
161         git submodule summary -n 3 >actual &&
162         cat >expected <<-EOF &&
163         * sm1 $head2...$head4 (4):
164           > Add foo5
165           > Add foo4
166           < Add foo3
167
168         EOF
169         test_cmp expected actual
170 "
171
172 commit_file sm1 &&
173 mv sm1 sm1-bak &&
174 echo sm1 >sm1 &&
175 head5=$(git hash-object sm1 | cut -c1-7) &&
176 git add sm1 &&
177 rm -f sm1 &&
178 mv sm1-bak sm1
179
180 test_expect_success 'typechanged submodule(submodule->blob), --cached' "
181         git submodule summary --cached >actual &&
182         cat >expected <<-EOF &&
183         * sm1 $head4(submodule)->$head5(blob) (3):
184           < Add foo5
185
186         EOF
187         test_i18ncmp expected actual
188 "
189
190 test_expect_success 'typechanged submodule(submodule->blob), --files' "
191         git submodule summary --files >actual &&
192         cat >expected <<-EOF &&
193         * sm1 $head5(blob)->$head4(submodule) (3):
194           > Add foo5
195
196         EOF
197         test_i18ncmp expected actual
198 "
199
200 rm -rf sm1 &&
201 git checkout-index sm1
202 test_expect_success 'typechanged submodule(submodule->blob)' "
203         git submodule summary >actual &&
204         cat >expected <<-EOF &&
205         * sm1 $head4(submodule)->$head5(blob):
206
207         EOF
208         test_i18ncmp expected actual
209 "
210
211 rm -f sm1 &&
212 test_create_repo sm1 &&
213 head6=$(add_file sm1 foo6 foo7)
214 test_expect_success 'nonexistent commit' "
215         git submodule summary >actual &&
216         cat >expected <<-EOF &&
217         * sm1 $head4...$head6:
218           Warn: sm1 doesn't contain commit $head4_full
219
220         EOF
221         test_i18ncmp expected actual
222 "
223
224 commit_file
225 test_expect_success 'typechanged submodule(blob->submodule)' "
226         git submodule summary >actual &&
227         cat >expected <<-EOF &&
228         * sm1 $head5(blob)->$head6(submodule) (2):
229           > Add foo7
230
231         EOF
232         test_i18ncmp expected actual
233 "
234
235 commit_file sm1 &&
236 rm -rf sm1
237 test_expect_success 'deleted submodule' "
238         git submodule summary >actual &&
239         cat >expected <<-EOF &&
240         * sm1 $head6...0000000:
241
242         EOF
243         test_cmp expected actual
244 "
245
246 test_expect_success 'create second submodule' '
247         test_create_repo sm2 &&
248         head7=$(add_file sm2 foo8 foo9) &&
249         git add sm2
250 '
251
252 test_expect_success 'multiple submodules' "
253         git submodule summary >actual &&
254         cat >expected <<-EOF &&
255         * sm1 $head6...0000000:
256
257         * sm2 0000000...$head7 (2):
258           > Add foo9
259
260         EOF
261         test_cmp expected actual
262 "
263
264 test_expect_success 'path filter' "
265         git submodule summary sm2 >actual &&
266         cat >expected <<-EOF &&
267         * sm2 0000000...$head7 (2):
268           > Add foo9
269
270         EOF
271         test_cmp expected actual
272 "
273
274 commit_file sm2
275 test_expect_success 'given commit' "
276         git submodule summary HEAD^ >actual &&
277         cat >expected <<-EOF &&
278         * sm1 $head6...0000000:
279
280         * sm2 0000000...$head7 (2):
281           > Add foo9
282
283         EOF
284         test_cmp expected actual
285 "
286
287 test_expect_success '--for-status' "
288         git submodule summary --for-status HEAD^ >actual &&
289         test_i18ncmp - actual <<-EOF
290         * sm1 $head6...0000000:
291
292         * sm2 0000000...$head7 (2):
293           > Add foo9
294
295         EOF
296 "
297
298 test_expect_success 'fail when using --files together with --cached' "
299         test_must_fail git submodule summary --files --cached
300 "
301
302 test_expect_success 'should not fail in an empty repo' "
303         git init xyzzy &&
304         cd xyzzy &&
305         git submodule summary >output 2>&1 &&
306         test_must_be_empty output
307 "
308
309 test_done