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