294584452bbc3226e631ce0b81c546b04cd8d992
1#!/bin/sh
2#
3# Copyright (c) 2008 Ping Yin
4#
5
6test_description='Summary support for submodules
7
8This test tries to verify the sanity of summary subcommand of git submodule.
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 &&
33add_file . foo >/dev/null
34
35head1=$(add_file sm1 foo1 foo2)
36
37test_expect_success 'added submodule' "
38 git add sm1 &&
39 git submodule summary >actual &&
40 diff actual - <<-EOF
41* sm1 0000000...$head1 (2):
42 > Add foo2
43
44EOF
45"
46
47commit_file sm1 &&
48head2=$(add_file sm1 foo3)
49
50test_expect_success 'modified submodule(forward)' "
51 git submodule summary >actual &&
52 diff actual - <<-EOF
53* sm1 $head1...$head2 (1):
54 > Add foo3
55
56EOF
57"
58
59test_expect_success 'modified submodule(forward), --files' "
60 git submodule summary --files >actual &&
61 diff actual - <<-EOF
62* sm1 $head1...$head2 (1):
63 > Add foo3
64
65EOF
66"
67
68commit_file sm1 &&
69head3=$(
70 cd sm1 &&
71 git reset --hard HEAD~2 >/dev/null &&
72 git rev-parse --verify HEAD | cut -c1-7
73)
74
75test_expect_success 'modified submodule(backward)' "
76 git submodule summary >actual &&
77 diff actual - <<-EOF
78* sm1 $head2...$head3 (2):
79 < Add foo3
80 < Add foo2
81
82EOF
83"
84
85head4=$(add_file sm1 foo4 foo5) &&
86head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD)
87test_expect_success 'modified submodule(backward and forward)' "
88 git submodule summary >actual &&
89 diff actual - <<-EOF
90* sm1 $head2...$head4 (4):
91 > Add foo5
92 > Add foo4
93 < Add foo3
94 < Add foo2
95
96EOF
97"
98
99test_expect_success '--summary-limit' "
100 git submodule summary -n 3 >actual &&
101 diff actual - <<-EOF
102* sm1 $head2...$head4 (4):
103 > Add foo5
104 > Add foo4
105 < Add foo3
106
107EOF
108"
109
110commit_file sm1 &&
111mv sm1 sm1-bak &&
112echo sm1 >sm1 &&
113head5=$(git hash-object sm1 | cut -c1-7) &&
114git add sm1 &&
115rm -f sm1 &&
116mv sm1-bak sm1
117
118test_expect_success 'typechanged submodule(submodule->blob), --cached' "
119 git submodule summary --cached >actual &&
120 diff actual - <<-EOF
121* sm1 $head4(submodule)->$head5(blob) (3):
122 < Add foo5
123
124EOF
125"
126
127test_expect_success 'typechanged submodule(submodule->blob), --files' "
128 git submodule summary --files >actual &&
129 diff actual - <<-EOF
130* sm1 $head5(blob)->$head4(submodule) (3):
131 > Add foo5
132
133EOF
134"
135
136rm -rf sm1 &&
137git checkout-index sm1
138test_expect_success 'typechanged submodule(submodule->blob)' "
139 git submodule summary >actual &&
140 diff actual - <<-EOF
141* sm1 $head4(submodule)->$head5(blob):
142
143EOF
144"
145
146rm -f sm1 &&
147test_create_repo sm1 &&
148head6=$(add_file sm1 foo6 foo7)
149test_expect_success 'nonexistent commit' "
150 git submodule summary >actual &&
151 diff actual - <<-EOF
152* sm1 $head4...$head6:
153 Warn: sm1 doesn't contain commit $head4_full
154
155EOF
156"
157
158commit_file
159test_expect_success 'typechanged submodule(blob->submodule)' "
160 git submodule summary >actual &&
161 diff actual - <<-EOF
162* sm1 $head5(blob)->$head6(submodule) (2):
163 > Add foo7
164
165EOF
166"
167
168commit_file sm1 &&
169rm -rf sm1
170test_expect_success 'deleted submodule' "
171 git submodule summary >actual &&
172 diff actual - <<-EOF
173* sm1 $head6...0000000:
174
175EOF
176"
177
178test_create_repo sm2 &&
179head7=$(add_file sm2 foo8 foo9) &&
180git add sm2
181
182test_expect_success 'multiple submodules' "
183 git submodule summary >actual &&
184 diff actual - <<-EOF
185* sm1 $head6...0000000:
186
187* sm2 0000000...$head7 (2):
188 > Add foo9
189
190EOF
191"
192
193test_expect_success 'path filter' "
194 git submodule summary sm2 >actual &&
195 diff actual - <<-EOF
196* sm2 0000000...$head7 (2):
197 > Add foo9
198
199EOF
200"
201
202commit_file sm2
203test_expect_success 'given commit' "
204 git submodule summary HEAD^ >actual &&
205 diff actual - <<-EOF
206* sm1 $head6...0000000:
207
208* sm2 0000000...$head7 (2):
209 > Add foo9
210
211EOF
212"
213
214test_expect_success '--for-status' "
215 git submodule summary --for-status HEAD^ >actual &&
216 test_cmp actual - <<EOF
217# Submodule changes to be committed:
218#
219# * sm1 $head6...0000000:
220#
221# * sm2 0000000...$head7 (2):
222# > Add foo9
223#
224EOF
225"
226
227test_expect_success 'fail when using --files together with --cached' "
228 test_must_fail git submodule summary --files --cached
229"
230
231test_expect_success 'should not fail in an empty repo' "
232 git init xyzzy &&
233 cd xyzzy &&
234 git submodule summary >output 2>&1 &&
235 test_cmp output /dev/null
236"
237
238test_done