]>
Commit | Line | Data |
---|---|---|
2da2ddc6 PY |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2008 Ping Yin | |
4 | # | |
5 | ||
6 | test_description='Summary support for submodules | |
7 | ||
47a528ad | 8 | This test tries to verify the sanity of summary subcommand of git submodule. |
2da2ddc6 PY |
9 | ' |
10 | ||
11 | . ./test-lib.sh | |
12 | ||
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" | |
26 | } | |
27 | commit_file () { | |
28 | test_tick && | |
29 | git commit "$@" -m "Commit $*" >/dev/null | |
30 | } | |
31 | ||
32 | test_create_repo sm1 && | |
02604e29 | 33 | add_file . foo >/dev/null |
2da2ddc6 PY |
34 | |
35 | head1=$(add_file sm1 foo1 foo2) | |
36 | ||
37 | test_expect_success 'added submodule' " | |
38 | git add sm1 && | |
39 | git submodule summary >actual && | |
f8d186bb | 40 | cat >expected <<-EOF && |
2da2ddc6 PY |
41 | * sm1 0000000...$head1 (2): |
42 | > Add foo2 | |
43 | ||
44 | EOF | |
f8d186bb | 45 | test_cmp expected actual |
2da2ddc6 PY |
46 | " |
47 | ||
48 | commit_file sm1 && | |
49 | head2=$(add_file sm1 foo3) | |
50 | ||
51 | test_expect_success 'modified submodule(forward)' " | |
52 | git submodule summary >actual && | |
f8d186bb | 53 | cat >expected <<-EOF && |
2da2ddc6 PY |
54 | * sm1 $head1...$head2 (1): |
55 | > Add foo3 | |
56 | ||
57 | EOF | |
f8d186bb | 58 | test_cmp expected actual |
2da2ddc6 PY |
59 | " |
60 | ||
1c244f6e JL |
61 | test_expect_success 'modified submodule(forward), --files' " |
62 | git submodule summary --files >actual && | |
f8d186bb | 63 | cat >expected <<-EOF && |
1c244f6e JL |
64 | * sm1 $head1...$head2 (1): |
65 | > Add foo3 | |
66 | ||
67 | EOF | |
f8d186bb | 68 | test_cmp expected actual |
1c244f6e JL |
69 | " |
70 | ||
2da2ddc6 | 71 | commit_file sm1 && |
18a82692 JN |
72 | head3=$( |
73 | cd sm1 && | |
74 | git reset --hard HEAD~2 >/dev/null && | |
75 | git rev-parse --verify HEAD | cut -c1-7 | |
fd4ec4f2 | 76 | ) |
2da2ddc6 PY |
77 | |
78 | test_expect_success 'modified submodule(backward)' " | |
79 | git submodule summary >actual && | |
f8d186bb | 80 | cat >expected <<-EOF && |
2da2ddc6 PY |
81 | * sm1 $head2...$head3 (2): |
82 | < Add foo3 | |
83 | < Add foo2 | |
84 | ||
85 | EOF | |
f8d186bb | 86 | test_cmp expected actual |
2da2ddc6 PY |
87 | " |
88 | ||
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 && | |
f8d186bb | 93 | cat >expected <<-EOF && |
2da2ddc6 PY |
94 | * sm1 $head2...$head4 (4): |
95 | > Add foo5 | |
96 | > Add foo4 | |
97 | < Add foo3 | |
98 | < Add foo2 | |
99 | ||
100 | EOF | |
f8d186bb | 101 | test_cmp expected actual |
2da2ddc6 PY |
102 | " |
103 | ||
104 | test_expect_success '--summary-limit' " | |
105 | git submodule summary -n 3 >actual && | |
f8d186bb | 106 | cat >expected <<-EOF && |
2da2ddc6 PY |
107 | * sm1 $head2...$head4 (4): |
108 | > Add foo5 | |
109 | > Add foo4 | |
110 | < Add foo3 | |
111 | ||
112 | EOF | |
f8d186bb | 113 | test_cmp expected actual |
2da2ddc6 PY |
114 | " |
115 | ||
116 | commit_file sm1 && | |
117 | mv sm1 sm1-bak && | |
118 | echo sm1 >sm1 && | |
119 | head5=$(git hash-object sm1 | cut -c1-7) && | |
120 | git add sm1 && | |
121 | rm -f sm1 && | |
122 | mv sm1-bak sm1 | |
123 | ||
124 | test_expect_success 'typechanged submodule(submodule->blob), --cached' " | |
125 | git submodule summary --cached >actual && | |
f8d186bb | 126 | cat >expected <<-EOF && |
2da2ddc6 PY |
127 | * sm1 $head4(submodule)->$head5(blob) (3): |
128 | < Add foo5 | |
129 | ||
130 | EOF | |
b3e73449 | 131 | test_i18ncmp actual expected |
2da2ddc6 PY |
132 | " |
133 | ||
1c244f6e JL |
134 | test_expect_success 'typechanged submodule(submodule->blob), --files' " |
135 | git submodule summary --files >actual && | |
f8d186bb | 136 | cat >expected <<-EOF && |
1c244f6e JL |
137 | * sm1 $head5(blob)->$head4(submodule) (3): |
138 | > Add foo5 | |
139 | ||
140 | EOF | |
b3e73449 | 141 | test_i18ncmp actual expected |
1c244f6e JL |
142 | " |
143 | ||
2da2ddc6 PY |
144 | rm -rf sm1 && |
145 | git checkout-index sm1 | |
146 | test_expect_success 'typechanged submodule(submodule->blob)' " | |
147 | git submodule summary >actual && | |
f8d186bb | 148 | cat >expected <<-EOF && |
2da2ddc6 PY |
149 | * sm1 $head4(submodule)->$head5(blob): |
150 | ||
151 | EOF | |
b3e73449 | 152 | test_i18ncmp actual expected |
2da2ddc6 PY |
153 | " |
154 | ||
155 | rm -f sm1 && | |
156 | test_create_repo sm1 && | |
157 | head6=$(add_file sm1 foo6 foo7) | |
158 | test_expect_success 'nonexistent commit' " | |
159 | git submodule summary >actual && | |
f8d186bb | 160 | cat >expected <<-EOF && |
2da2ddc6 PY |
161 | * sm1 $head4...$head6: |
162 | Warn: sm1 doesn't contain commit $head4_full | |
163 | ||
164 | EOF | |
f62f8212 | 165 | test_i18ncmp actual expected |
2da2ddc6 PY |
166 | " |
167 | ||
168 | commit_file | |
169 | test_expect_success 'typechanged submodule(blob->submodule)' " | |
170 | git submodule summary >actual && | |
f8d186bb | 171 | cat >expected <<-EOF && |
2da2ddc6 PY |
172 | * sm1 $head5(blob)->$head6(submodule) (2): |
173 | > Add foo7 | |
174 | ||
175 | EOF | |
b3e73449 | 176 | test_i18ncmp expected actual |
2da2ddc6 PY |
177 | " |
178 | ||
179 | commit_file sm1 && | |
180 | rm -rf sm1 | |
181 | test_expect_success 'deleted submodule' " | |
182 | git submodule summary >actual && | |
f8d186bb | 183 | cat >expected <<-EOF && |
2da2ddc6 PY |
184 | * sm1 $head6...0000000: |
185 | ||
186 | EOF | |
f8d186bb | 187 | test_cmp expected actual |
2da2ddc6 PY |
188 | " |
189 | ||
190 | test_create_repo sm2 && | |
191 | head7=$(add_file sm2 foo8 foo9) && | |
192 | git add sm2 | |
193 | ||
194 | test_expect_success 'multiple submodules' " | |
195 | git submodule summary >actual && | |
f8d186bb | 196 | cat >expected <<-EOF && |
2da2ddc6 PY |
197 | * sm1 $head6...0000000: |
198 | ||
199 | * sm2 0000000...$head7 (2): | |
200 | > Add foo9 | |
201 | ||
202 | EOF | |
f8d186bb | 203 | test_cmp expected actual |
2da2ddc6 PY |
204 | " |
205 | ||
206 | test_expect_success 'path filter' " | |
207 | git submodule summary sm2 >actual && | |
f8d186bb | 208 | cat >expected <<-EOF && |
2da2ddc6 PY |
209 | * sm2 0000000...$head7 (2): |
210 | > Add foo9 | |
211 | ||
212 | EOF | |
f8d186bb | 213 | test_cmp expected actual |
2da2ddc6 PY |
214 | " |
215 | ||
216 | commit_file sm2 | |
217 | test_expect_success 'given commit' " | |
218 | git submodule summary HEAD^ >actual && | |
f8d186bb | 219 | cat >expected <<-EOF && |
2da2ddc6 PY |
220 | * sm1 $head6...0000000: |
221 | ||
222 | * sm2 0000000...$head7 (2): | |
223 | > Add foo9 | |
224 | ||
225 | EOF | |
f8d186bb | 226 | test_cmp expected actual |
2da2ddc6 PY |
227 | " |
228 | ||
d0f64dd4 PY |
229 | test_expect_success '--for-status' " |
230 | git submodule summary --for-status HEAD^ >actual && | |
165119e9 | 231 | test_i18ncmp actual - <<EOF |
f17a5d34 | 232 | # Submodule changes to be committed: |
d0f64dd4 PY |
233 | # |
234 | # * sm1 $head6...0000000: | |
235 | # | |
236 | # * sm2 0000000...$head7 (2): | |
237 | # > Add foo9 | |
238 | # | |
239 | EOF | |
240 | " | |
241 | ||
1c244f6e JL |
242 | test_expect_success 'fail when using --files together with --cached' " |
243 | test_must_fail git submodule summary --files --cached | |
244 | " | |
245 | ||
3deea89c JH |
246 | test_expect_success 'should not fail in an empty repo' " |
247 | git init xyzzy && | |
248 | cd xyzzy && | |
249 | git submodule summary >output 2>&1 && | |
250 | test_cmp output /dev/null | |
251 | " | |
252 | ||
2da2ddc6 | 253 | test_done |