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.
19 echo "$name" > "$name" &&
22 git commit -m "Add $name"
24 git rev-parse --verify HEAD | cut -c1-7
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' "
39 git submodule summary >actual &&
40 cat >expected <<-EOF &&
41 * sm1 0000000...$head1 (2):
45 test_cmp expected actual
49 head2=$(add_file sm1 foo3)
51 test_expect_success 'modified submodule(forward)' "
52 git submodule summary >actual &&
53 cat >expected <<-EOF &&
54 * sm1 $head1...$head2 (1):
58 test_cmp expected actual
61 test_expect_success 'modified submodule(forward), --files' "
62 git submodule summary --files >actual &&
63 cat >expected <<-EOF &&
64 * sm1 $head1...$head2 (1):
68 test_cmp expected actual
74 git reset --hard HEAD~2 >/dev/null &&
75 git rev-parse --verify HEAD | cut -c1-7
78 test_expect_success 'modified submodule(backward)' "
79 git submodule summary >actual &&
80 cat >expected <<-EOF &&
81 * sm1 $head2...$head3 (2):
86 test_cmp expected actual
89 head4=$(add_file sm1 foo4 foo5) &&
90 head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD)
91 test_expect_success 'modified submodule(backward and forward)' "
92 git submodule summary >actual &&
93 cat >expected <<-EOF &&
94 * sm1 $head2...$head4 (4):
101 test_cmp expected actual
104 test_expect_success '--summary-limit' "
105 git submodule summary -n 3 >actual &&
106 cat >expected <<-EOF &&
107 * sm1 $head2...$head4 (4):
113 test_cmp expected actual
119 head5=$(git hash-object sm1 | cut -c1-7) &&
124 test_expect_success 'typechanged submodule(submodule->blob), --cached' "
125 git submodule summary --cached >actual &&
126 cat >expected <<-EOF &&
127 * sm1 $head4(submodule)->$head5(blob) (3):
131 test_i18ncmp actual expected
134 test_expect_success 'typechanged submodule(submodule->blob), --files' "
135 git submodule summary --files >actual &&
136 cat >expected <<-EOF &&
137 * sm1 $head5(blob)->$head4(submodule) (3):
141 test_i18ncmp actual expected
145 git checkout-index sm1
146 test_expect_success 'typechanged submodule(submodule->blob)' "
147 git submodule summary >actual &&
148 cat >expected <<-EOF &&
149 * sm1 $head4(submodule)->$head5(blob):
152 test_i18ncmp actual expected
156 test_create_repo sm1 &&
157 head6=$(add_file sm1 foo6 foo7)
158 test_expect_success 'nonexistent commit' "
159 git submodule summary >actual &&
160 cat >expected <<-EOF &&
161 * sm1 $head4...$head6:
162 Warn: sm1 doesn't contain commit $head4_full
165 test_i18ncmp actual expected
169 test_expect_success 'typechanged submodule(blob->submodule)' "
170 git submodule summary >actual &&
171 cat >expected <<-EOF &&
172 * sm1 $head5(blob)->$head6(submodule) (2):
176 test_i18ncmp expected actual
181 test_expect_success 'deleted submodule' "
182 git submodule summary >actual &&
183 cat >expected <<-EOF &&
184 * sm1 $head6...0000000:
187 test_cmp expected actual
190 test_create_repo sm2 &&
191 head7=$(add_file sm2 foo8 foo9) &&
194 test_expect_success 'multiple submodules' "
195 git submodule summary >actual &&
196 cat >expected <<-EOF &&
197 * sm1 $head6...0000000:
199 * sm2 0000000...$head7 (2):
203 test_cmp expected actual
206 test_expect_success 'path filter' "
207 git submodule summary sm2 >actual &&
208 cat >expected <<-EOF &&
209 * sm2 0000000...$head7 (2):
213 test_cmp expected actual
217 test_expect_success 'given commit' "
218 git submodule summary HEAD^ >actual &&
219 cat >expected <<-EOF &&
220 * sm1 $head6...0000000:
222 * sm2 0000000...$head7 (2):
226 test_cmp expected actual
229 test_expect_success '--for-status' "
230 git submodule summary --for-status HEAD^ >actual &&
231 test_i18ncmp actual - <<EOF
232 # Submodule changes to be committed:
234 # * sm1 $head6...0000000:
236 # * sm2 0000000...$head7 (2):
242 test_expect_success 'fail when using --files together with --cached' "
243 test_must_fail git submodule summary --files --cached
246 test_expect_success 'should not fail in an empty repo' "
249 git submodule summary >output 2>&1 &&
250 test_cmp output /dev/null