blob: 30b429e7dcbcd56af21ded67128aa18901133275 [file] [log] [blame]
Ping Yin2da2ddc2008-03-11 21:52:19 +08001#!/bin/sh
2#
3# Copyright (c) 2008 Ping Yin
4#
5
6test_description='Summary support for submodules
7
Nanako Shiraishi47a528a2008-09-03 17:59:33 +09008This test tries to verify the sanity of summary subcommand of git submodule.
Ping Yin2da2ddc2008-03-11 21:52:19 +08009'
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 &&
Junio C Hamano02604e22008-04-12 18:57:08 -070033add_file . foo >/dev/null
Ping Yin2da2ddc2008-03-11 21:52:19 +080034
35head1=$(add_file sm1 foo1 foo2)
36
37test_expect_success 'added submodule' "
38 git add sm1 &&
39 git submodule summary >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +000040 cat >expected <<-EOF &&
Ping Yin2da2ddc2008-03-11 21:52:19 +080041* sm1 0000000...$head1 (2):
42 > Add foo2
43
44EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +000045 test_cmp expected actual
Ping Yin2da2ddc2008-03-11 21:52:19 +080046"
47
48commit_file sm1 &&
49head2=$(add_file sm1 foo3)
50
51test_expect_success 'modified submodule(forward)' "
52 git submodule summary >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +000053 cat >expected <<-EOF &&
Ping Yin2da2ddc2008-03-11 21:52:19 +080054* sm1 $head1...$head2 (1):
55 > Add foo3
56
57EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +000058 test_cmp expected actual
Ping Yin2da2ddc2008-03-11 21:52:19 +080059"
60
Jens Lehmann1c244f62009-08-13 21:32:50 +020061test_expect_success 'modified submodule(forward), --files' "
62 git submodule summary --files >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +000063 cat >expected <<-EOF &&
Jens Lehmann1c244f62009-08-13 21:32:50 +020064* sm1 $head1...$head2 (1):
65 > Add foo3
66
67EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +000068 test_cmp expected actual
Jens Lehmann1c244f62009-08-13 21:32:50 +020069"
70
Ping Yin2da2ddc2008-03-11 21:52:19 +080071commit_file sm1 &&
Jonathan Nieder18a82692010-09-06 20:42:54 -050072head3=$(
73 cd sm1 &&
74 git reset --hard HEAD~2 >/dev/null &&
75 git rev-parse --verify HEAD | cut -c1-7
Jens Lehmannfd4ec4f2010-09-06 20:39:54 +020076)
Ping Yin2da2ddc2008-03-11 21:52:19 +080077
78test_expect_success 'modified submodule(backward)' "
79 git submodule summary >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +000080 cat >expected <<-EOF &&
Ping Yin2da2ddc2008-03-11 21:52:19 +080081* sm1 $head2...$head3 (2):
82 < Add foo3
83 < Add foo2
84
85EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +000086 test_cmp expected actual
Ping Yin2da2ddc2008-03-11 21:52:19 +080087"
88
89head4=$(add_file sm1 foo4 foo5) &&
90head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD)
91test_expect_success 'modified submodule(backward and forward)' "
92 git submodule summary >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +000093 cat >expected <<-EOF &&
Ping Yin2da2ddc2008-03-11 21:52:19 +080094* sm1 $head2...$head4 (4):
95 > Add foo5
96 > Add foo4
97 < Add foo3
98 < Add foo2
99
100EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000101 test_cmp expected actual
Ping Yin2da2ddc2008-03-11 21:52:19 +0800102"
103
104test_expect_success '--summary-limit' "
105 git submodule summary -n 3 >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000106 cat >expected <<-EOF &&
Ping Yin2da2ddc2008-03-11 21:52:19 +0800107* sm1 $head2...$head4 (4):
108 > Add foo5
109 > Add foo4
110 < Add foo3
111
112EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000113 test_cmp expected actual
Ping Yin2da2ddc2008-03-11 21:52:19 +0800114"
115
116commit_file sm1 &&
117mv sm1 sm1-bak &&
118echo sm1 >sm1 &&
119head5=$(git hash-object sm1 | cut -c1-7) &&
120git add sm1 &&
121rm -f sm1 &&
122mv sm1-bak sm1
123
124test_expect_success 'typechanged submodule(submodule->blob), --cached' "
125 git submodule summary --cached >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000126 cat >expected <<-EOF &&
Ping Yin2da2ddc2008-03-11 21:52:19 +0800127* sm1 $head4(submodule)->$head5(blob) (3):
128 < Add foo5
129
130EOF
Ævar Arnfjörð Bjarmasonb3e73442011-05-21 18:44:09 +0000131 test_i18ncmp actual expected
Ping Yin2da2ddc2008-03-11 21:52:19 +0800132"
133
Jens Lehmann1c244f62009-08-13 21:32:50 +0200134test_expect_success 'typechanged submodule(submodule->blob), --files' "
135 git submodule summary --files >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000136 cat >expected <<-EOF &&
Jens Lehmann1c244f62009-08-13 21:32:50 +0200137* sm1 $head5(blob)->$head4(submodule) (3):
138 > Add foo5
139
140EOF
Ævar Arnfjörð Bjarmasonb3e73442011-05-21 18:44:09 +0000141 test_i18ncmp actual expected
Jens Lehmann1c244f62009-08-13 21:32:50 +0200142"
143
Ping Yin2da2ddc2008-03-11 21:52:19 +0800144rm -rf sm1 &&
145git checkout-index sm1
146test_expect_success 'typechanged submodule(submodule->blob)' "
147 git submodule summary >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000148 cat >expected <<-EOF &&
Ping Yin2da2ddc2008-03-11 21:52:19 +0800149* sm1 $head4(submodule)->$head5(blob):
150
151EOF
Ævar Arnfjörð Bjarmasonb3e73442011-05-21 18:44:09 +0000152 test_i18ncmp actual expected
Ping Yin2da2ddc2008-03-11 21:52:19 +0800153"
154
155rm -f sm1 &&
156test_create_repo sm1 &&
157head6=$(add_file sm1 foo6 foo7)
158test_expect_success 'nonexistent commit' "
159 git submodule summary >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000160 cat >expected <<-EOF &&
Ping Yin2da2ddc2008-03-11 21:52:19 +0800161* sm1 $head4...$head6:
162 Warn: sm1 doesn't contain commit $head4_full
163
164EOF
Ævar Arnfjörð Bjarmasonf62f8212011-05-21 18:44:05 +0000165 test_i18ncmp actual expected
Ping Yin2da2ddc2008-03-11 21:52:19 +0800166"
167
168commit_file
169test_expect_success 'typechanged submodule(blob->submodule)' "
170 git submodule summary >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000171 cat >expected <<-EOF &&
Ping Yin2da2ddc2008-03-11 21:52:19 +0800172* sm1 $head5(blob)->$head6(submodule) (2):
173 > Add foo7
174
175EOF
Ævar Arnfjörð Bjarmasonb3e73442011-05-21 18:44:09 +0000176 test_i18ncmp expected actual
Ping Yin2da2ddc2008-03-11 21:52:19 +0800177"
178
179commit_file sm1 &&
180rm -rf sm1
181test_expect_success 'deleted submodule' "
182 git submodule summary >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000183 cat >expected <<-EOF &&
Ping Yin2da2ddc2008-03-11 21:52:19 +0800184* sm1 $head6...0000000:
185
186EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000187 test_cmp expected actual
Ping Yin2da2ddc2008-03-11 21:52:19 +0800188"
189
190test_create_repo sm2 &&
191head7=$(add_file sm2 foo8 foo9) &&
192git add sm2
193
194test_expect_success 'multiple submodules' "
195 git submodule summary >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000196 cat >expected <<-EOF &&
Ping Yin2da2ddc2008-03-11 21:52:19 +0800197* sm1 $head6...0000000:
198
199* sm2 0000000...$head7 (2):
200 > Add foo9
201
202EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000203 test_cmp expected actual
Ping Yin2da2ddc2008-03-11 21:52:19 +0800204"
205
206test_expect_success 'path filter' "
207 git submodule summary sm2 >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000208 cat >expected <<-EOF &&
Ping Yin2da2ddc2008-03-11 21:52:19 +0800209* sm2 0000000...$head7 (2):
210 > Add foo9
211
212EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000213 test_cmp expected actual
Ping Yin2da2ddc2008-03-11 21:52:19 +0800214"
215
216commit_file sm2
217test_expect_success 'given commit' "
218 git submodule summary HEAD^ >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000219 cat >expected <<-EOF &&
Ping Yin2da2ddc2008-03-11 21:52:19 +0800220* sm1 $head6...0000000:
221
222* sm2 0000000...$head7 (2):
223 > Add foo9
224
225EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000226 test_cmp expected actual
Ping Yin2da2ddc2008-03-11 21:52:19 +0800227"
228
Ping Yind0f64dd2008-04-12 23:05:31 +0800229test_expect_success '--for-status' "
230 git submodule summary --for-status HEAD^ >actual &&
Ævar Arnfjörð Bjarmason165119e2011-05-21 18:44:04 +0000231 test_i18ncmp actual - <<EOF
Jens Lehmannf17a5d32010-01-17 20:42:31 +0100232# Submodule changes to be committed:
Ping Yind0f64dd2008-04-12 23:05:31 +0800233#
234# * sm1 $head6...0000000:
235#
236# * sm2 0000000...$head7 (2):
237# > Add foo9
238#
239EOF
240"
241
Jens Lehmann1c244f62009-08-13 21:32:50 +0200242test_expect_success 'fail when using --files together with --cached' "
243 test_must_fail git submodule summary --files --cached
244"
245
Johan Herland3deea892010-02-16 11:21:14 +0100246test_expect_success 'should not fail in an empty repo' "
247 git init xyzzy &&
248 cd xyzzy &&
249 git submodule summary >output 2>&1 &&
250 test_cmp output /dev/null
251"
252
Ping Yin2da2ddc2008-03-11 21:52:19 +0800253test_done