rebase: use correct base for --keep-base when a branch is given
[alt-git.git] / t / t7401-submodule-summary.sh
blob9c3cc4cf4046befd76e0239c831d61b33196ee86
1 #!/bin/sh
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.
11 # NOTE: This test script uses 'git add' instead of 'git submodule add' to add
12 # submodules to the superproject. Some submodule subcommands such as init and
13 # deinit might not work as expected in this script. t7421 does not have this
14 # caveat.
16 # NEEDSWORK: This test script is old fashioned and may need a big cleanup due to
17 # various reasons, one of them being that there are lots of commands taking place
18 # outside of 'test_expect_success' block, which is no longer in good-style.
20 . ./test-lib.sh
22 add_file () {
23 sm=$1
24 shift
25 owd=$(pwd)
26 cd "$sm"
27 for name; do
28 echo "$name" >"$name" &&
29 git add "$name" &&
30 test_tick &&
31 git commit -m "Add $name"
32 done >/dev/null
33 git rev-parse --short HEAD
34 cd "$owd"
36 commit_file () {
37 test_tick &&
38 git commit "$@" -m "Commit $*" >/dev/null
41 test_create_repo sm1 &&
42 add_file . foo >/dev/null
44 head1=$(add_file sm1 foo1 foo2)
46 test_expect_success 'added submodule' "
47 git add sm1 &&
48 git submodule summary >actual &&
49 cat >expected <<-EOF &&
50 * sm1 0000000...$head1 (2):
51 > Add foo2
53 EOF
54 test_cmp expected actual
57 test_expect_success 'added submodule (subdirectory)' "
58 mkdir sub &&
60 cd sub &&
61 git submodule summary >../actual
62 ) &&
63 cat >expected <<-EOF &&
64 * ../sm1 0000000...$head1 (2):
65 > Add foo2
67 EOF
68 test_cmp expected actual
71 test_expect_success 'added submodule (subdirectory only)' "
73 cd sub &&
74 git submodule summary . >../actual
75 ) &&
76 test_must_be_empty actual
79 test_expect_success 'added submodule (subdirectory with explicit path)' "
81 cd sub &&
82 git submodule summary ../sm1 >../actual
83 ) &&
84 cat >expected <<-EOF &&
85 * ../sm1 0000000...$head1 (2):
86 > Add foo2
88 EOF
89 test_cmp expected actual
92 commit_file sm1 &&
93 head2=$(add_file sm1 foo3)
95 test_expect_success 'modified submodule(forward)' "
96 git submodule summary >actual &&
97 cat >expected <<-EOF &&
98 * sm1 $head1...$head2 (1):
99 > Add foo3
102 test_cmp expected actual
105 test_expect_success 'modified submodule(forward), --files' "
106 git submodule summary --files >actual &&
107 cat >expected <<-EOF &&
108 * sm1 $head1...$head2 (1):
109 > Add foo3
112 test_cmp expected actual
115 test_expect_success 'no ignore=all setting has any effect' "
116 git config -f .gitmodules submodule.sm1.path sm1 &&
117 git config -f .gitmodules submodule.sm1.ignore all &&
118 git config submodule.sm1.ignore all &&
119 git config diff.ignoreSubmodules all &&
120 git submodule summary >actual &&
121 cat >expected <<-EOF &&
122 * sm1 $head1...$head2 (1):
123 > Add foo3
126 test_cmp expected actual &&
127 git config --unset diff.ignoreSubmodules &&
128 git config --remove-section submodule.sm1 &&
129 git config -f .gitmodules --remove-section submodule.sm1
133 commit_file sm1 &&
134 head3=$(
135 cd sm1 &&
136 git reset --hard HEAD~2 >/dev/null &&
137 git rev-parse --short HEAD
140 test_expect_success 'modified submodule(backward)' "
141 git submodule summary >actual &&
142 cat >expected <<-EOF &&
143 * sm1 $head2...$head3 (2):
144 < Add foo3
145 < Add foo2
148 test_cmp expected actual
151 head4=$(add_file sm1 foo4 foo5) &&
152 head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD)
153 test_expect_success 'modified submodule(backward and forward)' "
154 git submodule summary >actual &&
155 cat >expected <<-EOF &&
156 * sm1 $head2...$head4 (4):
157 > Add foo5
158 > Add foo4
159 < Add foo3
160 < Add foo2
163 test_cmp expected actual
166 test_expect_success '--summary-limit' "
167 git submodule summary -n 3 >actual &&
168 cat >expected <<-EOF &&
169 * sm1 $head2...$head4 (4):
170 > Add foo5
171 > Add foo4
172 < Add foo3
175 test_cmp expected actual
178 commit_file sm1 &&
179 mv sm1 sm1-bak &&
180 echo sm1 >sm1 &&
181 head5=$(git hash-object sm1 | cut -c1-7) &&
182 git add sm1 &&
183 rm -f sm1 &&
184 mv sm1-bak sm1
186 test_expect_success 'typechanged submodule(submodule->blob), --cached' "
187 git submodule summary --cached >actual &&
188 cat >expected <<-EOF &&
189 * sm1 $head4(submodule)->$head5(blob) (3):
190 < Add foo5
193 test_cmp expected actual
196 test_expect_success 'typechanged submodule(submodule->blob), --files' "
197 git submodule summary --files >actual &&
198 cat >expected <<-EOF &&
199 * sm1 $head5(blob)->$head4(submodule) (3):
200 > Add foo5
203 test_cmp expected actual
206 rm -rf sm1 &&
207 git checkout-index sm1
208 test_expect_success 'typechanged submodule(submodule->blob)' "
209 git submodule summary >actual &&
210 cat >expected <<-EOF &&
211 * sm1 $head4(submodule)->$head5(blob):
214 test_cmp expected actual
217 rm -f sm1 &&
218 test_create_repo sm1 &&
219 head6=$(add_file sm1 foo6 foo7)
220 test_expect_success 'nonexistent commit' "
221 git submodule summary >actual &&
222 cat >expected <<-EOF &&
223 * sm1 $head4...$head6:
224 Warn: sm1 doesn't contain commit $head4_full
227 test_cmp expected actual
230 commit_file
231 test_expect_success 'typechanged submodule(blob->submodule)' "
232 git submodule summary >actual &&
233 cat >expected <<-EOF &&
234 * sm1 $head5(blob)->$head6(submodule) (2):
235 > Add foo7
238 test_cmp expected actual
241 commit_file sm1 &&
242 rm -rf sm1
243 test_expect_success 'deleted submodule' "
244 git submodule summary >actual &&
245 cat >expected <<-EOF &&
246 * sm1 $head6...0000000:
249 test_cmp expected actual
252 test_expect_success 'create second submodule' '
253 test_create_repo sm2 &&
254 head7=$(add_file sm2 foo8 foo9) &&
255 git add sm2
258 test_expect_success 'multiple submodules' "
259 git submodule summary >actual &&
260 cat >expected <<-EOF &&
261 * sm1 $head6...0000000:
263 * sm2 0000000...$head7 (2):
264 > Add foo9
267 test_cmp expected actual
270 test_expect_success 'path filter' "
271 git submodule summary sm2 >actual &&
272 cat >expected <<-EOF &&
273 * sm2 0000000...$head7 (2):
274 > Add foo9
277 test_cmp expected actual
280 commit_file sm2
281 test_expect_success 'given commit' "
282 git submodule summary HEAD^ >actual &&
283 cat >expected <<-EOF &&
284 * sm1 $head6...0000000:
286 * sm2 0000000...$head7 (2):
287 > Add foo9
290 test_cmp expected actual
293 test_expect_success '--for-status' "
294 git submodule summary --for-status HEAD^ >actual &&
295 test_cmp - actual <<-EOF
296 * sm1 $head6...0000000:
298 * sm2 0000000...$head7 (2):
299 > Add foo9
304 test_expect_success 'fail when using --files together with --cached' "
305 test_must_fail git submodule summary --files --cached
308 test_expect_success 'should not fail in an empty repo' "
309 git init xyzzy &&
310 cd xyzzy &&
311 git submodule summary >output 2>&1 &&
312 test_must_be_empty output
315 test_done