Merge branch 'master' of git://repo.or.cz/alt-git
[git/mingw.git] / t / t7401-submodule-summary.sh
blob7e06641a9771c3d7a6bd1e62b7b533b18a9125c1
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 head3=$(
74 cd sm1 &&
75 git reset --hard HEAD~2 >/dev/null &&
76 git rev-parse --verify HEAD | cut -c1-7
79 test_expect_success 'modified submodule(backward)' "
80 git submodule summary >actual &&
81 test_cmp actual - <<-EOF
82 * sm1 $head2...$head3 (2):
83 < Add foo3
84 < Add foo2
86 EOF
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 test_cmp actual - <<-EOF
94 * sm1 $head2...$head4 (4):
95 > Add foo5
96 > Add foo4
97 < Add foo3
98 < Add foo2
103 test_expect_success '--summary-limit' "
104 git submodule summary -n 3 >actual &&
105 test_cmp actual - <<-EOF
106 * sm1 $head2...$head4 (4):
107 > Add foo5
108 > Add foo4
109 < Add foo3
114 commit_file sm1 &&
115 mv sm1 sm1-bak &&
116 echo sm1 >sm1 &&
117 head5=$(git hash-object sm1 | cut -c1-7) &&
118 git add sm1 &&
119 rm -f sm1 &&
120 mv sm1-bak sm1
122 test_expect_success 'typechanged submodule(submodule->blob), --cached' "
123 git submodule summary --cached >actual &&
124 test_cmp actual - <<-EOF
125 * sm1 $head4(submodule)->$head5(blob) (3):
126 < Add foo5
131 test_expect_success 'typechanged submodule(submodule->blob), --files' "
132 git submodule summary --files >actual &&
133 diff actual - <<-EOF
134 * sm1 $head5(blob)->$head4(submodule) (3):
135 > Add foo5
140 rm -rf sm1 &&
141 git checkout-index sm1
142 test_expect_success 'typechanged submodule(submodule->blob)' "
143 git submodule summary >actual &&
144 test_cmp actual - <<-EOF
145 * sm1 $head4(submodule)->$head5(blob):
150 rm -f sm1 &&
151 test_create_repo sm1 &&
152 head6=$(add_file sm1 foo6 foo7)
153 test_expect_success 'nonexistent commit' "
154 git submodule summary >actual &&
155 test_cmp actual - <<-EOF
156 * sm1 $head4...$head6:
157 Warn: sm1 doesn't contain commit $head4_full
162 commit_file
163 test_expect_success 'typechanged submodule(blob->submodule)' "
164 git submodule summary >actual &&
165 test_cmp actual - <<-EOF
166 * sm1 $head5(blob)->$head6(submodule) (2):
167 > Add foo7
172 commit_file sm1 &&
173 rm -rf sm1
174 test_expect_success 'deleted submodule' "
175 git submodule summary >actual &&
176 test_cmp actual - <<-EOF
177 * sm1 $head6...0000000:
182 test_create_repo sm2 &&
183 head7=$(add_file sm2 foo8 foo9) &&
184 git add sm2
186 test_expect_success 'multiple submodules' "
187 git submodule summary >actual &&
188 test_cmp actual - <<-EOF
189 * sm1 $head6...0000000:
191 * sm2 0000000...$head7 (2):
192 > Add foo9
197 test_expect_success 'path filter' "
198 git submodule summary sm2 >actual &&
199 test_cmp actual - <<-EOF
200 * sm2 0000000...$head7 (2):
201 > Add foo9
206 commit_file sm2
207 test_expect_success 'given commit' "
208 git submodule summary HEAD^ >actual &&
209 test_cmp actual - <<-EOF
210 * sm1 $head6...0000000:
212 * sm2 0000000...$head7 (2):
213 > Add foo9
218 test_expect_success '--for-status' "
219 git submodule summary --for-status HEAD^ >actual &&
220 test_cmp actual - <<EOF
221 # Submodule changes to be committed:
223 # * sm1 $head6...0000000:
225 # * sm2 0000000...$head7 (2):
226 # > Add foo9
231 test_expect_success 'fail when using --files together with --cached' "
232 test_must_fail git submodule summary --files --cached
235 test_expect_success 'should not fail in an empty repo' "
236 git init xyzzy &&
237 cd xyzzy &&
238 git submodule summary >output 2>&1 &&
239 test_cmp output /dev/null
242 test_done