]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7401-submodule-summary.sh
hashmap: use *_entry APIs for iteration
[thirdparty/git.git] / t / t7401-submodule-summary.sh
CommitLineData
2da2ddc6
PY
1#!/bin/sh
2#
3# Copyright (c) 2008 Ping Yin
4#
5
6test_description='Summary support for submodules
7
47a528ad 8This test tries to verify the sanity of summary subcommand of git submodule.
2da2ddc6
PY
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 &&
02604e29 33add_file . foo >/dev/null
2da2ddc6
PY
34
35head1=$(add_file sm1 foo1 foo2)
36
37test_expect_success 'added submodule' "
38 git add sm1 &&
39 git submodule summary >actual &&
f8d186bb 40 cat >expected <<-EOF &&
2da2ddc6 41* sm1 0000000...$head1 (2):
091a6eb0
JK
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 ) &&
d3c6751b 67 test_must_be_empty actual
091a6eb0
JK
68"
69
70test_expect_success 'added submodule (subdirectory with explicit path)' "
71 (
72 cd sub &&
73 git submodule summary ../sm1 >../actual
74 ) &&
75 cat >expected <<-EOF &&
76* ../sm1 0000000...$head1 (2):
2da2ddc6
PY
77 > Add foo2
78
79EOF
f8d186bb 80 test_cmp expected actual
2da2ddc6
PY
81"
82
83commit_file sm1 &&
84head2=$(add_file sm1 foo3)
85
86test_expect_success 'modified submodule(forward)' "
87 git submodule summary >actual &&
f8d186bb 88 cat >expected <<-EOF &&
2da2ddc6
PY
89* sm1 $head1...$head2 (1):
90 > Add foo3
91
92EOF
f8d186bb 93 test_cmp expected actual
2da2ddc6
PY
94"
95
1c244f6e
JL
96test_expect_success 'modified submodule(forward), --files' "
97 git submodule summary --files >actual &&
f8d186bb 98 cat >expected <<-EOF &&
1c244f6e
JL
99* sm1 $head1...$head2 (1):
100 > Add foo3
101
102EOF
f8d186bb 103 test_cmp expected actual
1c244f6e
JL
104"
105
927b26f8 106test_expect_success 'no ignore=all setting has any effect' "
107 git config -f .gitmodules submodule.sm1.path sm1 &&
108 git config -f .gitmodules submodule.sm1.ignore all &&
109 git config submodule.sm1.ignore all &&
110 git config diff.ignoreSubmodules all &&
111 git submodule summary >actual &&
112 cat >expected <<-EOF &&
113* sm1 $head1...$head2 (1):
114 > Add foo3
115
116EOF
117 test_cmp expected actual &&
118 git config --unset diff.ignoreSubmodules &&
119 git config --remove-section submodule.sm1 &&
120 git config -f .gitmodules --remove-section submodule.sm1
121"
122
123
2da2ddc6 124commit_file sm1 &&
18a82692
JN
125head3=$(
126 cd sm1 &&
127 git reset --hard HEAD~2 >/dev/null &&
128 git rev-parse --verify HEAD | cut -c1-7
fd4ec4f2 129)
2da2ddc6
PY
130
131test_expect_success 'modified submodule(backward)' "
8120e421
JK
132 git submodule summary >actual &&
133 cat >expected <<-EOF &&
2da2ddc6
PY
134* sm1 $head2...$head3 (2):
135 < Add foo3
136 < Add foo2
137
138EOF
f8d186bb 139 test_cmp expected actual
2da2ddc6
PY
140"
141
142head4=$(add_file sm1 foo4 foo5) &&
143head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD)
144test_expect_success 'modified submodule(backward and forward)' "
8120e421
JK
145 git submodule summary >actual &&
146 cat >expected <<-EOF &&
2da2ddc6
PY
147* sm1 $head2...$head4 (4):
148 > Add foo5
149 > Add foo4
150 < Add foo3
151 < Add foo2
152
153EOF
f8d186bb 154 test_cmp expected actual
2da2ddc6
PY
155"
156
157test_expect_success '--summary-limit' "
8120e421
JK
158 git submodule summary -n 3 >actual &&
159 cat >expected <<-EOF &&
2da2ddc6
PY
160* sm1 $head2...$head4 (4):
161 > Add foo5
162 > Add foo4
163 < Add foo3
164
165EOF
8120e421 166 test_cmp expected actual
2da2ddc6
PY
167"
168
169commit_file sm1 &&
170mv sm1 sm1-bak &&
171echo sm1 >sm1 &&
172head5=$(git hash-object sm1 | cut -c1-7) &&
173git add sm1 &&
174rm -f sm1 &&
175mv sm1-bak sm1
176
177test_expect_success 'typechanged submodule(submodule->blob), --cached' "
8120e421
JK
178 git submodule summary --cached >actual &&
179 cat >expected <<-EOF &&
2da2ddc6
PY
180* sm1 $head4(submodule)->$head5(blob) (3):
181 < Add foo5
182
183EOF
b3e73449 184 test_i18ncmp actual expected
2da2ddc6
PY
185"
186
1c244f6e 187test_expect_success 'typechanged submodule(submodule->blob), --files' "
8120e421
JK
188 git submodule summary --files >actual &&
189 cat >expected <<-EOF &&
1c244f6e
JL
190* sm1 $head5(blob)->$head4(submodule) (3):
191 > Add foo5
192
193EOF
8120e421 194 test_i18ncmp actual expected
1c244f6e
JL
195"
196
2da2ddc6
PY
197rm -rf sm1 &&
198git checkout-index sm1
199test_expect_success 'typechanged submodule(submodule->blob)' "
8120e421
JK
200 git submodule summary >actual &&
201 cat >expected <<-EOF &&
2da2ddc6
PY
202* sm1 $head4(submodule)->$head5(blob):
203
204EOF
8120e421 205 test_i18ncmp actual expected
2da2ddc6
PY
206"
207
208rm -f sm1 &&
209test_create_repo sm1 &&
210head6=$(add_file sm1 foo6 foo7)
211test_expect_success 'nonexistent commit' "
8120e421
JK
212 git submodule summary >actual &&
213 cat >expected <<-EOF &&
2da2ddc6
PY
214* sm1 $head4...$head6:
215 Warn: sm1 doesn't contain commit $head4_full
216
217EOF
8120e421 218 test_i18ncmp actual expected
2da2ddc6
PY
219"
220
221commit_file
222test_expect_success 'typechanged submodule(blob->submodule)' "
8120e421
JK
223 git submodule summary >actual &&
224 cat >expected <<-EOF &&
2da2ddc6
PY
225* sm1 $head5(blob)->$head6(submodule) (2):
226 > Add foo7
227
228EOF
8120e421 229 test_i18ncmp expected actual
2da2ddc6
PY
230"
231
232commit_file sm1 &&
233rm -rf sm1
234test_expect_success 'deleted submodule' "
8120e421
JK
235 git submodule summary >actual &&
236 cat >expected <<-EOF &&
2da2ddc6
PY
237* sm1 $head6...0000000:
238
239EOF
8120e421 240 test_cmp expected actual
2da2ddc6
PY
241"
242
17f2f88c
JK
243test_expect_success 'create second submodule' '
244 test_create_repo sm2 &&
245 head7=$(add_file sm2 foo8 foo9) &&
246 git add sm2
247'
2da2ddc6
PY
248
249test_expect_success 'multiple submodules' "
8120e421
JK
250 git submodule summary >actual &&
251 cat >expected <<-EOF &&
2da2ddc6
PY
252* sm1 $head6...0000000:
253
254* sm2 0000000...$head7 (2):
255 > Add foo9
256
257EOF
8120e421 258 test_cmp expected actual
2da2ddc6
PY
259"
260
261test_expect_success 'path filter' "
8120e421
JK
262 git submodule summary sm2 >actual &&
263 cat >expected <<-EOF &&
2da2ddc6
PY
264* sm2 0000000...$head7 (2):
265 > Add foo9
266
267EOF
8120e421 268 test_cmp expected actual
2da2ddc6
PY
269"
270
271commit_file sm2
272test_expect_success 'given commit' "
8120e421
JK
273 git submodule summary HEAD^ >actual &&
274 cat >expected <<-EOF &&
2da2ddc6
PY
275* sm1 $head6...0000000:
276
277* sm2 0000000...$head7 (2):
278 > Add foo9
279
280EOF
8120e421 281 test_cmp expected actual
2da2ddc6
PY
282"
283
d0f64dd4 284test_expect_success '--for-status' "
8120e421
JK
285 git submodule summary --for-status HEAD^ >actual &&
286 test_i18ncmp actual - <<EOF
3ba7407b
MM
287* sm1 $head6...0000000:
288
289* sm2 0000000...$head7 (2):
290 > Add foo9
291
d0f64dd4
PY
292EOF
293"
294
1c244f6e 295test_expect_success 'fail when using --files together with --cached' "
8120e421 296 test_must_fail git submodule summary --files --cached
1c244f6e
JL
297"
298
3deea89c 299test_expect_success 'should not fail in an empty repo' "
8120e421
JK
300 git init xyzzy &&
301 cd xyzzy &&
302 git submodule summary >output 2>&1 &&
ec21ac8c 303 test_must_be_empty output
3deea89c
JH
304"
305
2da2ddc6 306test_done