Git 1.7.3 rc1
[git/mingw/4msysgit/kblees.git] / t / t7401-submodule-summary.sh
blobcee319da0ae6ef9ec3b220adbb178e116713db2a
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 diff actual - <<-EOF
41 * sm1 0000000...$head1 (2):
42 > Add foo2
44 EOF
47 commit_file sm1 &&
48 head2=$(add_file sm1 foo3)
50 test_expect_success 'modified submodule(forward)' "
51 git submodule summary >actual &&
52 diff actual - <<-EOF
53 * sm1 $head1...$head2 (1):
54 > Add foo3
56 EOF
59 test_expect_success 'modified submodule(forward), --files' "
60 git submodule summary --files >actual &&
61 diff actual - <<-EOF
62 * sm1 $head1...$head2 (1):
63 > Add foo3
65 EOF
68 commit_file sm1 &&
69 cd sm1 &&
70 git reset --hard HEAD~2 >/dev/null &&
71 head3=$(git rev-parse --verify HEAD | cut -c1-7) &&
72 cd ..
74 test_expect_success 'modified submodule(backward)' "
75 git submodule summary >actual &&
76 diff actual - <<-EOF
77 * sm1 $head2...$head3 (2):
78 < Add foo3
79 < Add foo2
81 EOF
84 head4=$(add_file sm1 foo4 foo5) &&
85 head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD)
86 test_expect_success 'modified submodule(backward and forward)' "
87 git submodule summary >actual &&
88 diff actual - <<-EOF
89 * sm1 $head2...$head4 (4):
90 > Add foo5
91 > Add foo4
92 < Add foo3
93 < Add foo2
95 EOF
98 test_expect_success '--summary-limit' "
99 git submodule summary -n 3 >actual &&
100 diff actual - <<-EOF
101 * sm1 $head2...$head4 (4):
102 > Add foo5
103 > Add foo4
104 < Add foo3
109 commit_file sm1 &&
110 mv sm1 sm1-bak &&
111 echo sm1 >sm1 &&
112 head5=$(git hash-object sm1 | cut -c1-7) &&
113 git add sm1 &&
114 rm -f sm1 &&
115 mv sm1-bak sm1
117 test_expect_success 'typechanged submodule(submodule->blob), --cached' "
118 git submodule summary --cached >actual &&
119 diff actual - <<-EOF
120 * sm1 $head4(submodule)->$head5(blob) (3):
121 < Add foo5
126 test_expect_success 'typechanged submodule(submodule->blob), --files' "
127 git submodule summary --files >actual &&
128 diff actual - <<-EOF
129 * sm1 $head5(blob)->$head4(submodule) (3):
130 > Add foo5
135 rm -rf sm1 &&
136 git checkout-index sm1
137 test_expect_success 'typechanged submodule(submodule->blob)' "
138 git submodule summary >actual &&
139 diff actual - <<-EOF
140 * sm1 $head4(submodule)->$head5(blob):
145 rm -f sm1 &&
146 test_create_repo sm1 &&
147 head6=$(add_file sm1 foo6 foo7)
148 test_expect_success 'nonexistent commit' "
149 git submodule summary >actual &&
150 diff actual - <<-EOF
151 * sm1 $head4...$head6:
152 Warn: sm1 doesn't contain commit $head4_full
157 commit_file
158 test_expect_success 'typechanged submodule(blob->submodule)' "
159 git submodule summary >actual &&
160 diff actual - <<-EOF
161 * sm1 $head5(blob)->$head6(submodule) (2):
162 > Add foo7
167 commit_file sm1 &&
168 rm -rf sm1
169 test_expect_success 'deleted submodule' "
170 git submodule summary >actual &&
171 diff actual - <<-EOF
172 * sm1 $head6...0000000:
177 test_create_repo sm2 &&
178 head7=$(add_file sm2 foo8 foo9) &&
179 git add sm2
181 test_expect_success 'multiple submodules' "
182 git submodule summary >actual &&
183 diff actual - <<-EOF
184 * sm1 $head6...0000000:
186 * sm2 0000000...$head7 (2):
187 > Add foo9
192 test_expect_success 'path filter' "
193 git submodule summary sm2 >actual &&
194 diff actual - <<-EOF
195 * sm2 0000000...$head7 (2):
196 > Add foo9
201 commit_file sm2
202 test_expect_success 'given commit' "
203 git submodule summary HEAD^ >actual &&
204 diff actual - <<-EOF
205 * sm1 $head6...0000000:
207 * sm2 0000000...$head7 (2):
208 > Add foo9
213 test_expect_success '--for-status' "
214 git submodule summary --for-status HEAD^ >actual &&
215 test_cmp actual - <<EOF
216 # Submodule changes to be committed:
218 # * sm1 $head6...0000000:
220 # * sm2 0000000...$head7 (2):
221 # > Add foo9
226 test_expect_success 'fail when using --files together with --cached' "
227 test_must_fail git submodule summary --files --cached
230 test_expect_success 'should not fail in an empty repo' "
231 git init xyzzy &&
232 cd xyzzy &&
233 git submodule summary >output 2>&1 &&
234 test_cmp output /dev/null
237 test_done