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.
10 # NEEDSWORK: This test script is old fashioned and may need a big cleanup due to
11 # various reasons, one of them being that there are lots of commands taking place
12 # outside of 'test_expect_success' block, which is no longer in good-style.
22 echo "$name" >"$name" &&
25 git commit -m "Add $name"
27 git rev-parse --short HEAD
32 git commit "$@" -m "Commit $*" >/dev/null
35 test_create_repo sm1 &&
36 add_file . foo >/dev/null
38 head1=$(add_file sm1 foo1 foo2)
40 test_expect_success 'added submodule' "
42 git submodule summary >actual &&
43 cat >expected <<-EOF &&
44 * sm1 0000000...$head1 (2):
48 test_cmp expected actual
51 test_expect_success 'added submodule (subdirectory)' "
55 git submodule summary >../actual
57 cat >expected <<-EOF &&
58 * ../sm1 0000000...$head1 (2):
62 test_cmp expected actual
65 test_expect_success 'added submodule (subdirectory only)' "
68 git submodule summary . >../actual
70 test_must_be_empty actual
73 test_expect_success 'added submodule (subdirectory with explicit path)' "
76 git submodule summary ../sm1 >../actual
78 cat >expected <<-EOF &&
79 * ../sm1 0000000...$head1 (2):
83 test_cmp expected actual
87 head2=$(add_file sm1 foo3)
89 test_expect_success 'modified submodule(forward)' "
90 git submodule summary >actual &&
91 cat >expected <<-EOF &&
92 * sm1 $head1...$head2 (1):
96 test_cmp expected actual
99 test_expect_success 'modified submodule(forward), --files' "
100 git submodule summary --files >actual &&
101 cat >expected <<-EOF &&
102 * sm1 $head1...$head2 (1):
106 test_cmp expected actual
109 test_expect_success 'no ignore=all setting has any effect' "
110 git config -f .gitmodules submodule.sm1.path sm1 &&
111 git config -f .gitmodules submodule.sm1.ignore all &&
112 git config submodule.sm1.ignore all &&
113 git config diff.ignoreSubmodules all &&
114 git submodule summary >actual &&
115 cat >expected <<-EOF &&
116 * sm1 $head1...$head2 (1):
120 test_cmp expected actual &&
121 git config --unset diff.ignoreSubmodules &&
122 git config --remove-section submodule.sm1 &&
123 git config -f .gitmodules --remove-section submodule.sm1
130 git reset --hard HEAD~2 >/dev/null &&
131 git rev-parse --short HEAD
134 test_expect_success 'modified submodule(backward)' "
135 git submodule summary >actual &&
136 cat >expected <<-EOF &&
137 * sm1 $head2...$head3 (2):
142 test_cmp expected actual
145 head4=$(add_file sm1 foo4 foo5) &&
146 head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD)
147 test_expect_success 'modified submodule(backward and forward)' "
148 git submodule summary >actual &&
149 cat >expected <<-EOF &&
150 * sm1 $head2...$head4 (4):
157 test_cmp expected actual
160 test_expect_success '--summary-limit' "
161 git submodule summary -n 3 >actual &&
162 cat >expected <<-EOF &&
163 * sm1 $head2...$head4 (4):
169 test_cmp expected actual
175 head5=$(git hash-object sm1 | cut -c1-7) &&
180 test_expect_success 'typechanged submodule(submodule->blob), --cached' "
181 git submodule summary --cached >actual &&
182 cat >expected <<-EOF &&
183 * sm1 $head4(submodule)->$head5(blob) (3):
187 test_i18ncmp expected actual
190 test_expect_success 'typechanged submodule(submodule->blob), --files' "
191 git submodule summary --files >actual &&
192 cat >expected <<-EOF &&
193 * sm1 $head5(blob)->$head4(submodule) (3):
197 test_i18ncmp expected actual
201 git checkout-index sm1
202 test_expect_success 'typechanged submodule(submodule->blob)' "
203 git submodule summary >actual &&
204 cat >expected <<-EOF &&
205 * sm1 $head4(submodule)->$head5(blob):
208 test_i18ncmp expected actual
212 test_create_repo sm1 &&
213 head6=$(add_file sm1 foo6 foo7)
214 test_expect_success 'nonexistent commit' "
215 git submodule summary >actual &&
216 cat >expected <<-EOF &&
217 * sm1 $head4...$head6:
218 Warn: sm1 doesn't contain commit $head4_full
221 test_i18ncmp expected actual
225 test_expect_success 'typechanged submodule(blob->submodule)' "
226 git submodule summary >actual &&
227 cat >expected <<-EOF &&
228 * sm1 $head5(blob)->$head6(submodule) (2):
232 test_i18ncmp expected actual
237 test_expect_success 'deleted submodule' "
238 git submodule summary >actual &&
239 cat >expected <<-EOF &&
240 * sm1 $head6...0000000:
243 test_cmp expected actual
246 test_expect_success 'create second submodule' '
247 test_create_repo sm2 &&
248 head7=$(add_file sm2 foo8 foo9) &&
252 test_expect_success 'multiple submodules' "
253 git submodule summary >actual &&
254 cat >expected <<-EOF &&
255 * sm1 $head6...0000000:
257 * sm2 0000000...$head7 (2):
261 test_cmp expected actual
264 test_expect_success 'path filter' "
265 git submodule summary sm2 >actual &&
266 cat >expected <<-EOF &&
267 * sm2 0000000...$head7 (2):
271 test_cmp expected actual
275 test_expect_success 'given commit' "
276 git submodule summary HEAD^ >actual &&
277 cat >expected <<-EOF &&
278 * sm1 $head6...0000000:
280 * sm2 0000000...$head7 (2):
284 test_cmp expected actual
287 test_expect_success '--for-status' "
288 git submodule summary --for-status HEAD^ >actual &&
289 test_i18ncmp - actual <<-EOF
290 * sm1 $head6...0000000:
292 * sm2 0000000...$head7 (2):
298 test_expect_success 'fail when using --files together with --cached' "
299 test_must_fail git submodule summary --files --cached
302 test_expect_success 'should not fail in an empty repo' "
305 git submodule summary >output 2>&1 &&
306 test_must_be_empty output