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.
10 # NOTE: This test script uses 'git add' instead of 'git submodule add' to add
11 # submodules to the superproject. Some submodule subcommands such as init and
12 # deinit might not work as expected in this script. t7421 does not have this
23 echo "$name" > "$name" &&
26 git commit -m "Add $name"
28 git rev-parse --verify HEAD | cut -c1-7
33 git commit "$@" -m "Commit $*" >/dev/null
36 test_create_repo sm1 &&
37 add_file . foo >/dev/null
39 head1=$(add_file sm1 foo1 foo2)
41 test_expect_success 'added submodule' "
43 git submodule summary >actual &&
44 cat >expected <<-EOF &&
45 * sm1 0000000...$head1 (2):
49 test_cmp expected actual
52 test_expect_success 'added submodule (subdirectory)' "
56 git submodule summary >../actual
58 cat >expected <<-EOF &&
59 * ../sm1 0000000...$head1 (2):
63 test_cmp expected actual
66 test_expect_success 'added submodule (subdirectory only)' "
69 git submodule summary . >../actual
71 test_must_be_empty actual
74 test_expect_success 'added submodule (subdirectory with explicit path)' "
77 git submodule summary ../sm1 >../actual
79 cat >expected <<-EOF &&
80 * ../sm1 0000000...$head1 (2):
84 test_cmp expected actual
88 head2=$(add_file sm1 foo3)
90 test_expect_success 'modified submodule(forward)' "
91 git submodule summary >actual &&
92 cat >expected <<-EOF &&
93 * sm1 $head1...$head2 (1):
97 test_cmp expected actual
100 test_expect_success 'modified submodule(forward), --files' "
101 git submodule summary --files >actual &&
102 cat >expected <<-EOF &&
103 * sm1 $head1...$head2 (1):
107 test_cmp expected actual
110 test_expect_success 'no ignore=all setting has any effect' "
111 git config -f .gitmodules submodule.sm1.path sm1 &&
112 git config -f .gitmodules submodule.sm1.ignore all &&
113 git config submodule.sm1.ignore all &&
114 git config diff.ignoreSubmodules all &&
115 git submodule summary >actual &&
116 cat >expected <<-EOF &&
117 * sm1 $head1...$head2 (1):
121 test_cmp expected actual &&
122 git config --unset diff.ignoreSubmodules &&
123 git config --remove-section submodule.sm1 &&
124 git config -f .gitmodules --remove-section submodule.sm1
131 git reset --hard HEAD~2 >/dev/null &&
132 git rev-parse --verify HEAD | cut -c1-7
135 test_expect_success 'modified submodule(backward)' "
136 git submodule summary >actual &&
137 cat >expected <<-EOF &&
138 * sm1 $head2...$head3 (2):
143 test_cmp expected actual
146 head4=$(add_file sm1 foo4 foo5) &&
147 head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD)
148 test_expect_success 'modified submodule(backward and forward)' "
149 git submodule summary >actual &&
150 cat >expected <<-EOF &&
151 * sm1 $head2...$head4 (4):
158 test_cmp expected actual
161 test_expect_success '--summary-limit' "
162 git submodule summary -n 3 >actual &&
163 cat >expected <<-EOF &&
164 * sm1 $head2...$head4 (4):
170 test_cmp expected actual
176 head5=$(git hash-object sm1 | cut -c1-7) &&
181 test_expect_success 'typechanged submodule(submodule->blob), --cached' "
182 git submodule summary --cached >actual &&
183 cat >expected <<-EOF &&
184 * sm1 $head4(submodule)->$head5(blob) (3):
188 test_i18ncmp actual expected
191 test_expect_success 'typechanged submodule(submodule->blob), --files' "
192 git submodule summary --files >actual &&
193 cat >expected <<-EOF &&
194 * sm1 $head5(blob)->$head4(submodule) (3):
198 test_i18ncmp actual expected
202 git checkout-index sm1
203 test_expect_success 'typechanged submodule(submodule->blob)' "
204 git submodule summary >actual &&
205 cat >expected <<-EOF &&
206 * sm1 $head4(submodule)->$head5(blob):
209 test_i18ncmp actual expected
213 test_create_repo sm1 &&
214 head6=$(add_file sm1 foo6 foo7)
215 test_expect_success 'nonexistent commit' "
216 git submodule summary >actual &&
217 cat >expected <<-EOF &&
218 * sm1 $head4...$head6:
219 Warn: sm1 doesn't contain commit $head4_full
222 test_i18ncmp actual expected
226 test_expect_success 'typechanged submodule(blob->submodule)' "
227 git submodule summary >actual &&
228 cat >expected <<-EOF &&
229 * sm1 $head5(blob)->$head6(submodule) (2):
233 test_i18ncmp expected actual
238 test_expect_success 'deleted submodule' "
239 git submodule summary >actual &&
240 cat >expected <<-EOF &&
241 * sm1 $head6...0000000:
244 test_cmp expected actual
247 test_expect_success 'create second submodule' '
248 test_create_repo sm2 &&
249 head7=$(add_file sm2 foo8 foo9) &&
253 test_expect_success 'multiple submodules' "
254 git submodule summary >actual &&
255 cat >expected <<-EOF &&
256 * sm1 $head6...0000000:
258 * sm2 0000000...$head7 (2):
262 test_cmp expected actual
265 test_expect_success 'path filter' "
266 git submodule summary sm2 >actual &&
267 cat >expected <<-EOF &&
268 * sm2 0000000...$head7 (2):
272 test_cmp expected actual
276 test_expect_success 'given commit' "
277 git submodule summary HEAD^ >actual &&
278 cat >expected <<-EOF &&
279 * sm1 $head6...0000000:
281 * sm2 0000000...$head7 (2):
285 test_cmp expected actual
288 test_expect_success '--for-status' "
289 git submodule summary --for-status HEAD^ >actual &&
290 test_i18ncmp actual - <<EOF
291 * sm1 $head6...0000000:
293 * sm2 0000000...$head7 (2):
299 test_expect_success 'fail when using --files together with --cached' "
300 test_must_fail git submodule summary --files --cached
303 test_expect_success 'should not fail in an empty repo' "
306 git submodule summary >output 2>&1 &&
307 test_must_be_empty output