Merge branch 'ml/cygwin-does-not-have-fifo'
[git/jrn.git] / t / t7401-submodule-summary.sh
blobac2434c0dbdaf837d8dd7f896e680fbb7b6ab954
1 #!/bin/sh
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.
11 . ./test-lib.sh
13 add_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"
27 commit_file () {
28 test_tick &&
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' "
38 git add sm1 &&
39 git submodule summary >actual &&
40 cat >expected <<-EOF &&
41 * sm1 0000000...$head1 (2):
42 > Add foo2
44 EOF
45 test_cmp expected actual
48 test_expect_success 'added submodule (subdirectory)' "
49 mkdir sub &&
51 cd sub &&
52 git submodule summary >../actual
53 ) &&
54 cat >expected <<-EOF &&
55 * ../sm1 0000000...$head1 (2):
56 > Add foo2
58 EOF
59 test_cmp expected actual
62 test_expect_success 'added submodule (subdirectory only)' "
64 cd sub &&
65 git submodule summary . >../actual
66 ) &&
67 >expected &&
68 test_cmp expected actual
71 test_expect_success 'added submodule (subdirectory with explicit path)' "
73 cd sub &&
74 git submodule summary ../sm1 >../actual
75 ) &&
76 cat >expected <<-EOF &&
77 * ../sm1 0000000...$head1 (2):
78 > Add foo2
80 EOF
81 test_cmp expected actual
84 commit_file sm1 &&
85 head2=$(add_file sm1 foo3)
87 test_expect_success 'modified submodule(forward)' "
88 git submodule summary >actual &&
89 cat >expected <<-EOF &&
90 * sm1 $head1...$head2 (1):
91 > Add foo3
93 EOF
94 test_cmp expected actual
97 test_expect_success 'modified submodule(forward), --files' "
98 git submodule summary --files >actual &&
99 cat >expected <<-EOF &&
100 * sm1 $head1...$head2 (1):
101 > Add foo3
104 test_cmp expected actual
107 commit_file sm1 &&
108 head3=$(
109 cd sm1 &&
110 git reset --hard HEAD~2 >/dev/null &&
111 git rev-parse --verify HEAD | cut -c1-7
114 test_expect_success 'modified submodule(backward)' "
115 git submodule summary >actual &&
116 cat >expected <<-EOF &&
117 * sm1 $head2...$head3 (2):
118 < Add foo3
119 < Add foo2
122 test_cmp expected actual
125 head4=$(add_file sm1 foo4 foo5) &&
126 head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD)
127 test_expect_success 'modified submodule(backward and forward)' "
128 git submodule summary >actual &&
129 cat >expected <<-EOF &&
130 * sm1 $head2...$head4 (4):
131 > Add foo5
132 > Add foo4
133 < Add foo3
134 < Add foo2
137 test_cmp expected actual
140 test_expect_success '--summary-limit' "
141 git submodule summary -n 3 >actual &&
142 cat >expected <<-EOF &&
143 * sm1 $head2...$head4 (4):
144 > Add foo5
145 > Add foo4
146 < Add foo3
149 test_cmp expected actual
152 commit_file sm1 &&
153 mv sm1 sm1-bak &&
154 echo sm1 >sm1 &&
155 head5=$(git hash-object sm1 | cut -c1-7) &&
156 git add sm1 &&
157 rm -f sm1 &&
158 mv sm1-bak sm1
160 test_expect_success 'typechanged submodule(submodule->blob), --cached' "
161 git submodule summary --cached >actual &&
162 cat >expected <<-EOF &&
163 * sm1 $head4(submodule)->$head5(blob) (3):
164 < Add foo5
167 test_i18ncmp actual expected
170 test_expect_success 'typechanged submodule(submodule->blob), --files' "
171 git submodule summary --files >actual &&
172 cat >expected <<-EOF &&
173 * sm1 $head5(blob)->$head4(submodule) (3):
174 > Add foo5
177 test_i18ncmp actual expected
180 rm -rf sm1 &&
181 git checkout-index sm1
182 test_expect_success 'typechanged submodule(submodule->blob)' "
183 git submodule summary >actual &&
184 cat >expected <<-EOF &&
185 * sm1 $head4(submodule)->$head5(blob):
188 test_i18ncmp actual expected
191 rm -f sm1 &&
192 test_create_repo sm1 &&
193 head6=$(add_file sm1 foo6 foo7)
194 test_expect_success 'nonexistent commit' "
195 git submodule summary >actual &&
196 cat >expected <<-EOF &&
197 * sm1 $head4...$head6:
198 Warn: sm1 doesn't contain commit $head4_full
201 test_i18ncmp actual expected
204 commit_file
205 test_expect_success 'typechanged submodule(blob->submodule)' "
206 git submodule summary >actual &&
207 cat >expected <<-EOF &&
208 * sm1 $head5(blob)->$head6(submodule) (2):
209 > Add foo7
212 test_i18ncmp expected actual
215 commit_file sm1 &&
216 rm -rf sm1
217 test_expect_success 'deleted submodule' "
218 git submodule summary >actual &&
219 cat >expected <<-EOF &&
220 * sm1 $head6...0000000:
223 test_cmp expected actual
226 test_create_repo sm2 &&
227 head7=$(add_file sm2 foo8 foo9) &&
228 git add sm2
230 test_expect_success 'multiple submodules' "
231 git submodule summary >actual &&
232 cat >expected <<-EOF &&
233 * sm1 $head6...0000000:
235 * sm2 0000000...$head7 (2):
236 > Add foo9
239 test_cmp expected actual
242 test_expect_success 'path filter' "
243 git submodule summary sm2 >actual &&
244 cat >expected <<-EOF &&
245 * sm2 0000000...$head7 (2):
246 > Add foo9
249 test_cmp expected actual
252 commit_file sm2
253 test_expect_success 'given commit' "
254 git submodule summary HEAD^ >actual &&
255 cat >expected <<-EOF &&
256 * sm1 $head6...0000000:
258 * sm2 0000000...$head7 (2):
259 > Add foo9
262 test_cmp expected actual
265 test_expect_success '--for-status' "
266 git submodule summary --for-status HEAD^ >actual &&
267 test_i18ncmp actual - <<EOF
268 # Submodule changes to be committed:
270 # * sm1 $head6...0000000:
272 # * sm2 0000000...$head7 (2):
273 # > Add foo9
278 test_expect_success 'fail when using --files together with --cached' "
279 test_must_fail git submodule summary --files --cached
282 test_expect_success 'should not fail in an empty repo' "
283 git init xyzzy &&
284 cd xyzzy &&
285 git submodule summary >output 2>&1 &&
286 test_cmp output /dev/null
289 test_done