Sync with maint
[git/debian.git] / t / t7401-submodule-summary.sh
blob4e4c45550262ca75b36d15e80aa1f4bffc45465f
1 #!/bin/sh
3 # Copyright (c) 2008 Ping Yin
6 test_description='Summary support for submodules
8 This test tries to verify the sanity of summary subcommand of git submodule.
11 . ./test-lib.sh
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"
27 commit_file () {
28 test_tick &&
29 git commit "$@" -m "Commit $*" >/dev/null
32 test_create_repo sm1 &&
33 add_file . foo >/dev/null
35 head1=$(add_file sm1 foo1 foo2)
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
44 EOF
45 test_cmp expected actual
48 test_expect_success 'added submodule (subdirectory)' "
49 mkdir sub &&
51 cd sub &&
52 git submodule summary >../actual
53 ) &&
54 cat >expected <<-EOF &&
55 * ../sm1 0000000...$head1 (2):
56 > Add foo2
58 EOF
59 test_cmp expected actual
62 test_expect_success 'added submodule (subdirectory only)' "
64 cd sub &&
65 git submodule summary . >../actual
66 ) &&
67 >expected &&
68 test_cmp expected actual
71 test_expect_success 'added submodule (subdirectory with explicit path)' "
73 cd sub &&
74 git submodule summary ../sm1 >../actual
75 ) &&
76 cat >expected <<-EOF &&
77 * ../sm1 0000000...$head1 (2):
78 > Add foo2
80 EOF
81 test_cmp expected actual
84 commit_file sm1 &&
85 head2=$(add_file sm1 foo3)
87 test_expect_success 'modified submodule(forward)' "
88 git submodule summary >actual &&
89 cat >expected <<-EOF &&
90 * sm1 $head1...$head2 (1):
91 > Add foo3
93 EOF
94 test_cmp expected actual
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
104 test_cmp expected actual
107 test_expect_success 'no ignore=all setting has any effect' "
108 git config -f .gitmodules submodule.sm1.path sm1 &&
109 git config -f .gitmodules submodule.sm1.ignore all &&
110 git config submodule.sm1.ignore all &&
111 git config diff.ignoreSubmodules all &&
112 git submodule summary >actual &&
113 cat >expected <<-EOF &&
114 * sm1 $head1...$head2 (1):
115 > Add foo3
118 test_cmp expected actual &&
119 git config --unset diff.ignoreSubmodules &&
120 git config --remove-section submodule.sm1 &&
121 git config -f .gitmodules --remove-section submodule.sm1
125 commit_file sm1 &&
126 head3=$(
127 cd sm1 &&
128 git reset --hard HEAD~2 >/dev/null &&
129 git rev-parse --verify HEAD | cut -c1-7
132 test_expect_success 'modified submodule(backward)' "
133 git submodule summary >actual &&
134 cat >expected <<-EOF &&
135 * sm1 $head2...$head3 (2):
136 < Add foo3
137 < Add foo2
140 test_cmp expected actual
143 head4=$(add_file sm1 foo4 foo5) &&
144 head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD)
145 test_expect_success 'modified submodule(backward and forward)' "
146 git submodule summary >actual &&
147 cat >expected <<-EOF &&
148 * sm1 $head2...$head4 (4):
149 > Add foo5
150 > Add foo4
151 < Add foo3
152 < Add foo2
155 test_cmp expected actual
158 test_expect_success '--summary-limit' "
159 git submodule summary -n 3 >actual &&
160 cat >expected <<-EOF &&
161 * sm1 $head2...$head4 (4):
162 > Add foo5
163 > Add foo4
164 < Add foo3
167 test_cmp expected actual
170 commit_file sm1 &&
171 mv sm1 sm1-bak &&
172 echo sm1 >sm1 &&
173 head5=$(git hash-object sm1 | cut -c1-7) &&
174 git add sm1 &&
175 rm -f sm1 &&
176 mv sm1-bak sm1
178 test_expect_success 'typechanged submodule(submodule->blob), --cached' "
179 git submodule summary --cached >actual &&
180 cat >expected <<-EOF &&
181 * sm1 $head4(submodule)->$head5(blob) (3):
182 < Add foo5
185 test_i18ncmp actual expected
188 test_expect_success 'typechanged submodule(submodule->blob), --files' "
189 git submodule summary --files >actual &&
190 cat >expected <<-EOF &&
191 * sm1 $head5(blob)->$head4(submodule) (3):
192 > Add foo5
195 test_i18ncmp actual expected
198 rm -rf sm1 &&
199 git checkout-index sm1
200 test_expect_success 'typechanged submodule(submodule->blob)' "
201 git submodule summary >actual &&
202 cat >expected <<-EOF &&
203 * sm1 $head4(submodule)->$head5(blob):
206 test_i18ncmp actual expected
209 rm -f sm1 &&
210 test_create_repo sm1 &&
211 head6=$(add_file sm1 foo6 foo7)
212 test_expect_success 'nonexistent commit' "
213 git submodule summary >actual &&
214 cat >expected <<-EOF &&
215 * sm1 $head4...$head6:
216 Warn: sm1 doesn't contain commit $head4_full
219 test_i18ncmp actual expected
222 commit_file
223 test_expect_success 'typechanged submodule(blob->submodule)' "
224 git submodule summary >actual &&
225 cat >expected <<-EOF &&
226 * sm1 $head5(blob)->$head6(submodule) (2):
227 > Add foo7
230 test_i18ncmp expected actual
233 commit_file sm1 &&
234 rm -rf sm1
235 test_expect_success 'deleted submodule' "
236 git submodule summary >actual &&
237 cat >expected <<-EOF &&
238 * sm1 $head6...0000000:
241 test_cmp expected actual
244 test_expect_success 'create second submodule' '
245 test_create_repo sm2 &&
246 head7=$(add_file sm2 foo8 foo9) &&
247 git add sm2
250 test_expect_success 'multiple submodules' "
251 git submodule summary >actual &&
252 cat >expected <<-EOF &&
253 * sm1 $head6...0000000:
255 * sm2 0000000...$head7 (2):
256 > Add foo9
259 test_cmp expected actual
262 test_expect_success 'path filter' "
263 git submodule summary sm2 >actual &&
264 cat >expected <<-EOF &&
265 * sm2 0000000...$head7 (2):
266 > Add foo9
269 test_cmp expected actual
272 commit_file sm2
273 test_expect_success 'given commit' "
274 git submodule summary HEAD^ >actual &&
275 cat >expected <<-EOF &&
276 * sm1 $head6...0000000:
278 * sm2 0000000...$head7 (2):
279 > Add foo9
282 test_cmp expected actual
285 test_expect_success '--for-status' "
286 git submodule summary --for-status HEAD^ >actual &&
287 test_i18ncmp actual - <<EOF
288 * sm1 $head6...0000000:
290 * sm2 0000000...$head7 (2):
291 > Add foo9
296 test_expect_success 'fail when using --files together with --cached' "
297 test_must_fail git submodule summary --files --cached
300 test_expect_success 'should not fail in an empty repo' "
301 git init xyzzy &&
302 cd xyzzy &&
303 git submodule summary >output 2>&1 &&
304 test_cmp output /dev/null
307 test_done