Merge branch 'jk/upload-pack-keepalive'
[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 tries to verify the sanity of summary subcommand of git submodule.
9 '
10
11 . ./test-lib.sh
12
13 add_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 }
27 commit_file () {
28         test_tick &&
29         git commit "$@" -m "Commit $*" >/dev/null
30 }
31
32 test_create_repo sm1 &&
33 add_file . foo >/dev/null
34
35 head1=$(add_file sm1 foo1 foo2)
36
37 test_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
44 EOF
45         test_cmp expected actual
46 "
47
48 test_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
58 EOF
59         test_cmp expected actual
60 "
61
62 test_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
71 test_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
80 EOF
81         test_cmp expected actual
82 "
83
84 commit_file sm1 &&
85 head2=$(add_file sm1 foo3)
86
87 test_expect_success 'modified submodule(forward)' "
88         git submodule summary >actual &&
89         cat >expected <<-EOF &&
90 * sm1 $head1...$head2 (1):
91   > Add foo3
92
93 EOF
94         test_cmp expected actual
95 "
96
97 test_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
103 EOF
104         test_cmp expected actual
105 "
106
107 commit_file sm1 &&
108 head3=$(
109         cd sm1 &&
110         git reset --hard HEAD~2 >/dev/null &&
111         git rev-parse --verify HEAD | cut -c1-7
112 )
113
114 test_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
121 EOF
122         test_cmp expected actual
123 "
124
125 head4=$(add_file sm1 foo4 foo5) &&
126 head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD)
127 test_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
136 EOF
137         test_cmp expected actual
138 "
139
140 test_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
148 EOF
149         test_cmp expected actual
150 "
151
152 commit_file sm1 &&
153 mv sm1 sm1-bak &&
154 echo sm1 >sm1 &&
155 head5=$(git hash-object sm1 | cut -c1-7) &&
156 git add sm1 &&
157 rm -f sm1 &&
158 mv sm1-bak sm1
159
160 test_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
166 EOF
167         test_i18ncmp actual expected
168 "
169
170 test_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
176 EOF
177         test_i18ncmp actual expected
178 "
179
180 rm -rf sm1 &&
181 git checkout-index sm1
182 test_expect_success 'typechanged submodule(submodule->blob)' "
183         git submodule summary >actual &&
184         cat >expected <<-EOF &&
185 * sm1 $head4(submodule)->$head5(blob):
186
187 EOF
188         test_i18ncmp actual expected
189 "
190
191 rm -f sm1 &&
192 test_create_repo sm1 &&
193 head6=$(add_file sm1 foo6 foo7)
194 test_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
200 EOF
201         test_i18ncmp actual expected
202 "
203
204 commit_file
205 test_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
211 EOF
212         test_i18ncmp expected actual
213 "
214
215 commit_file sm1 &&
216 rm -rf sm1
217 test_expect_success 'deleted submodule' "
218         git submodule summary >actual &&
219         cat >expected <<-EOF &&
220 * sm1 $head6...0000000:
221
222 EOF
223         test_cmp expected actual
224 "
225
226 test_create_repo sm2 &&
227 head7=$(add_file sm2 foo8 foo9) &&
228 git add sm2
229
230 test_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
238 EOF
239         test_cmp expected actual
240 "
241
242 test_expect_success 'path filter' "
243         git submodule summary sm2 >actual &&
244         cat >expected <<-EOF &&
245 * sm2 0000000...$head7 (2):
246   > Add foo9
247
248 EOF
249         test_cmp expected actual
250 "
251
252 commit_file sm2
253 test_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
261 EOF
262         test_cmp expected actual
263 "
264
265 test_expect_success '--for-status' "
266         git submodule summary --for-status HEAD^ >actual &&
267         test_i18ncmp actual - <<EOF
268 * sm1 $head6...0000000:
269
270 * sm2 0000000...$head7 (2):
271   > Add foo9
272
273 EOF
274 "
275
276 test_expect_success 'fail when using --files together with --cached' "
277         test_must_fail git submodule summary --files --cached
278 "
279
280 test_expect_success 'should not fail in an empty repo' "
281         git init xyzzy &&
282         cd xyzzy &&
283         git submodule summary >output 2>&1 &&
284         test_cmp output /dev/null
285 "
286
287 test_done