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