Merge branch 'master' of git://repo.or.cz/alt-git
[git/dscho.git] / t / t7401-submodule-summary.sh
blob485d726c50d730278239b86d12488ae71e8bbf21
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 case $(uname -s) in
12 *MINGW*) GIT_TEST_CMP="diff -uw";;
13 esac
15 . ./test-lib.sh
17 add_file () {
18 sm=$1
19 shift
20 owd=$(pwd)
21 cd "$sm"
22 for name; do
23 echo "$name" > "$name" &&
24 git add "$name" &&
25 test_tick &&
26 git commit -m "Add $name"
27 done >/dev/null
28 git rev-parse --verify HEAD | cut -c1-7
29 cd "$owd"
31 commit_file () {
32 test_tick &&
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' "
42 git add sm1 &&
43 git submodule summary >actual &&
44 test_cmp actual - <<-EOF
45 * sm1 0000000...$head1 (2):
46 > Add foo2
48 EOF
51 commit_file sm1 &&
52 head2=$(add_file sm1 foo3)
54 test_expect_success 'modified submodule(forward)' "
55 git submodule summary >actual &&
56 test_cmp actual - <<-EOF
57 * sm1 $head1...$head2 (1):
58 > Add foo3
60 EOF
63 test_expect_success 'modified submodule(forward), --files' "
64 git submodule summary --files >actual &&
65 diff actual - <<-EOF
66 * sm1 $head1...$head2 (1):
67 > Add foo3
69 EOF
72 commit_file sm1 &&
73 cd sm1 &&
74 git reset --hard HEAD~2 >/dev/null &&
75 head3=$(git rev-parse --verify HEAD | cut -c1-7) &&
76 cd ..
78 test_expect_success 'modified submodule(backward)' "
79 git submodule summary >actual &&
80 test_cmp actual - <<-EOF
81 * sm1 $head2...$head3 (2):
82 < Add foo3
83 < Add foo2
85 EOF
88 head4=$(add_file sm1 foo4 foo5) &&
89 head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD)
90 test_expect_success 'modified submodule(backward and forward)' "
91 git submodule summary >actual &&
92 test_cmp actual - <<-EOF
93 * sm1 $head2...$head4 (4):
94 > Add foo5
95 > Add foo4
96 < Add foo3
97 < Add foo2
99 EOF
102 test_expect_success '--summary-limit' "
103 git submodule summary -n 3 >actual &&
104 test_cmp actual - <<-EOF
105 * sm1 $head2...$head4 (4):
106 > Add foo5
107 > Add foo4
108 < Add foo3
113 commit_file sm1 &&
114 mv sm1 sm1-bak &&
115 echo sm1 >sm1 &&
116 head5=$(git hash-object sm1 | cut -c1-7) &&
117 git add sm1 &&
118 rm -f sm1 &&
119 mv sm1-bak sm1
121 test_expect_success 'typechanged submodule(submodule->blob), --cached' "
122 git submodule summary --cached >actual &&
123 test_cmp actual - <<-EOF
124 * sm1 $head4(submodule)->$head5(blob) (3):
125 < Add foo5
130 test_expect_success 'typechanged submodule(submodule->blob), --files' "
131 git submodule summary --files >actual &&
132 diff actual - <<-EOF
133 * sm1 $head5(blob)->$head4(submodule) (3):
134 > Add foo5
139 rm -rf sm1 &&
140 git checkout-index sm1
141 test_expect_success 'typechanged submodule(submodule->blob)' "
142 git submodule summary >actual &&
143 test_cmp actual - <<-EOF
144 * sm1 $head4(submodule)->$head5(blob):
149 rm -f sm1 &&
150 test_create_repo sm1 &&
151 head6=$(add_file sm1 foo6 foo7)
152 test_expect_success 'nonexistent commit' "
153 git submodule summary >actual &&
154 test_cmp actual - <<-EOF
155 * sm1 $head4...$head6:
156 Warn: sm1 doesn't contain commit $head4_full
161 commit_file
162 test_expect_success 'typechanged submodule(blob->submodule)' "
163 git submodule summary >actual &&
164 test_cmp actual - <<-EOF
165 * sm1 $head5(blob)->$head6(submodule) (2):
166 > Add foo7
171 commit_file sm1 &&
172 rm -rf sm1
173 test_expect_success 'deleted submodule' "
174 git submodule summary >actual &&
175 test_cmp actual - <<-EOF
176 * sm1 $head6...0000000:
181 test_create_repo sm2 &&
182 head7=$(add_file sm2 foo8 foo9) &&
183 git add sm2
185 test_expect_success 'multiple submodules' "
186 git submodule summary >actual &&
187 test_cmp actual - <<-EOF
188 * sm1 $head6...0000000:
190 * sm2 0000000...$head7 (2):
191 > Add foo9
196 test_expect_success 'path filter' "
197 git submodule summary sm2 >actual &&
198 test_cmp actual - <<-EOF
199 * sm2 0000000...$head7 (2):
200 > Add foo9
205 commit_file sm2
206 test_expect_success 'given commit' "
207 git submodule summary HEAD^ >actual &&
208 test_cmp actual - <<-EOF
209 * sm1 $head6...0000000:
211 * sm2 0000000...$head7 (2):
212 > Add foo9
217 test_expect_success '--for-status' "
218 git submodule summary --for-status HEAD^ >actual &&
219 test_cmp actual - <<EOF
220 # Submodule changes to be committed:
222 # * sm1 $head6...0000000:
224 # * sm2 0000000...$head7 (2):
225 # > Add foo9
230 test_expect_success 'fail when using --files together with --cached' "
231 test_must_fail git submodule summary --files --cached
234 test_done