t7800: improve test descriptions with empty arguments
[alt-git.git] / t / t7401-submodule-summary.sh
blob542b3331a78f4db27dc5d99d3364f780f4db4548
1 #!/bin/sh
3 # Copyright (c) 2008 Ping Yin
6 test_description='Summary support for submodules
8 This test script tries to verify the sanity of summary subcommand of git submodule.
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.
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.
20 TEST_PASSES_SANITIZE_LEAK=true
21 . ./test-lib.sh
23 add_file () {
24 sm=$1
25 shift
26 owd=$(pwd)
27 cd "$sm"
28 for name; do
29 echo "$name" >"$name" &&
30 git add "$name" &&
31 test_tick &&
32 git commit -m "Add $name"
33 done >/dev/null
34 git rev-parse --short HEAD
35 cd "$owd"
37 commit_file () {
38 test_tick &&
39 git commit "$@" -m "Commit $*" >/dev/null
42 test_create_repo sm1 &&
43 add_file . foo >/dev/null
45 head1=$(add_file sm1 foo1 foo2)
47 test_expect_success 'added submodule' "
48 git add sm1 &&
49 git submodule summary >actual &&
50 cat >expected <<-EOF &&
51 * sm1 0000000...$head1 (2):
52 > Add foo2
54 EOF
55 test_cmp expected actual
58 test_expect_success 'added submodule (subdirectory)' "
59 mkdir sub &&
61 cd sub &&
62 git submodule summary >../actual
63 ) &&
64 cat >expected <<-EOF &&
65 * ../sm1 0000000...$head1 (2):
66 > Add foo2
68 EOF
69 test_cmp expected actual
72 test_expect_success 'added submodule (subdirectory only)' "
74 cd sub &&
75 git submodule summary . >../actual
76 ) &&
77 test_must_be_empty actual
80 test_expect_success 'added submodule (subdirectory with explicit path)' "
82 cd sub &&
83 git submodule summary ../sm1 >../actual
84 ) &&
85 cat >expected <<-EOF &&
86 * ../sm1 0000000...$head1 (2):
87 > Add foo2
89 EOF
90 test_cmp expected actual
93 commit_file sm1 &&
94 head2=$(add_file sm1 foo3)
96 test_expect_success 'modified submodule(forward)' "
97 git submodule summary >actual &&
98 cat >expected <<-EOF &&
99 * sm1 $head1...$head2 (1):
100 > Add foo3
103 test_cmp expected actual
106 test_expect_success 'modified submodule(forward), --files' "
107 git submodule summary --files >actual &&
108 cat >expected <<-EOF &&
109 * sm1 $head1...$head2 (1):
110 > Add foo3
113 test_cmp expected actual
116 test_expect_success 'no ignore=all setting has any effect' "
117 git config -f .gitmodules submodule.sm1.path sm1 &&
118 git config -f .gitmodules submodule.sm1.ignore all &&
119 git config submodule.sm1.ignore all &&
120 git config diff.ignoreSubmodules all &&
121 git submodule summary >actual &&
122 cat >expected <<-EOF &&
123 * sm1 $head1...$head2 (1):
124 > Add foo3
127 test_cmp expected actual &&
128 git config --unset diff.ignoreSubmodules &&
129 git config --remove-section submodule.sm1 &&
130 git config -f .gitmodules --remove-section submodule.sm1
134 commit_file sm1 &&
135 head3=$(
136 cd sm1 &&
137 git reset --hard HEAD~2 >/dev/null &&
138 git rev-parse --short HEAD
141 test_expect_success 'modified submodule(backward)' "
142 git submodule summary >actual &&
143 cat >expected <<-EOF &&
144 * sm1 $head2...$head3 (2):
145 < Add foo3
146 < Add foo2
149 test_cmp expected actual
152 head4=$(add_file sm1 foo4 foo5) &&
153 head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD)
154 test_expect_success 'modified submodule(backward and forward)' "
155 git submodule summary >actual &&
156 cat >expected <<-EOF &&
157 * sm1 $head2...$head4 (4):
158 > Add foo5
159 > Add foo4
160 < Add foo3
161 < Add foo2
164 test_cmp expected actual
167 test_expect_success '--summary-limit' "
168 git submodule summary -n 3 >actual &&
169 cat >expected <<-EOF &&
170 * sm1 $head2...$head4 (4):
171 > Add foo5
172 > Add foo4
173 < Add foo3
176 test_cmp expected actual
179 commit_file sm1 &&
180 mv sm1 sm1-bak &&
181 echo sm1 >sm1 &&
182 head5=$(git hash-object sm1 | cut -c1-7) &&
183 git add sm1 &&
184 rm -f sm1 &&
185 mv sm1-bak sm1
187 test_expect_success 'typechanged submodule(submodule->blob), --cached' "
188 git submodule summary --cached >actual &&
189 cat >expected <<-EOF &&
190 * sm1 $head4(submodule)->$head5(blob) (3):
191 < Add foo5
194 test_cmp expected actual
197 test_expect_success 'typechanged submodule(submodule->blob), --files' "
198 git submodule summary --files >actual &&
199 cat >expected <<-EOF &&
200 * sm1 $head5(blob)->$head4(submodule) (3):
201 > Add foo5
204 test_cmp expected actual
207 rm -rf sm1 &&
208 git checkout-index sm1
209 test_expect_success 'typechanged submodule(submodule->blob)' "
210 git submodule summary >actual &&
211 cat >expected <<-EOF &&
212 * sm1 $head4(submodule)->$head5(blob):
215 test_cmp expected actual
218 rm -f sm1 &&
219 test_create_repo sm1 &&
220 head6=$(add_file sm1 foo6 foo7)
221 test_expect_success 'nonexistent commit' "
222 git submodule summary >actual &&
223 cat >expected <<-EOF &&
224 * sm1 $head4...$head6:
225 Warn: sm1 doesn't contain commit $head4_full
228 test_cmp expected actual
231 commit_file
232 test_expect_success 'typechanged submodule(blob->submodule)' "
233 git submodule summary >actual &&
234 cat >expected <<-EOF &&
235 * sm1 $head5(blob)->$head6(submodule) (2):
236 > Add foo7
239 test_cmp expected actual
242 commit_file sm1 &&
243 rm -rf sm1
244 test_expect_success 'deleted submodule' "
245 git submodule summary >actual &&
246 cat >expected <<-EOF &&
247 * sm1 $head6...0000000:
250 test_cmp expected actual
253 test_expect_success 'create second submodule' '
254 test_create_repo sm2 &&
255 head7=$(add_file sm2 foo8 foo9) &&
256 git add sm2
259 test_expect_success 'multiple submodules' "
260 git submodule summary >actual &&
261 cat >expected <<-EOF &&
262 * sm1 $head6...0000000:
264 * sm2 0000000...$head7 (2):
265 > Add foo9
268 test_cmp expected actual
271 test_expect_success 'path filter' "
272 git submodule summary sm2 >actual &&
273 cat >expected <<-EOF &&
274 * sm2 0000000...$head7 (2):
275 > Add foo9
278 test_cmp expected actual
281 commit_file sm2
282 test_expect_success 'given commit' "
283 git submodule summary HEAD^ >actual &&
284 cat >expected <<-EOF &&
285 * sm1 $head6...0000000:
287 * sm2 0000000...$head7 (2):
288 > Add foo9
291 test_cmp expected actual
294 test_expect_success '--for-status' "
295 git submodule summary --for-status HEAD^ >actual &&
296 test_cmp - actual <<-EOF
297 * sm1 $head6...0000000:
299 * sm2 0000000...$head7 (2):
300 > Add foo9
305 test_expect_success 'fail when using --files together with --cached' "
306 test_must_fail git submodule summary --files --cached
309 test_expect_success 'should not fail in an empty repo' "
310 git init xyzzy &&
311 cd xyzzy &&
312 git submodule summary >output 2>&1 &&
313 test_must_be_empty output
316 test_done