t0000: modernise style

Match the style to more modern test scripts, namely: - Prefer tabs for indentation. - The first line of each test has prereq, title and opening sq for the script body. - Move cleanup or initialization of data used by a test inside the test itself. - Put a newline before the closing sq for each test. - Don't conclude the test descriptions with a full stop. - Prefer 'test_line_count = COUNT FILE' over 'test $(wc -l <FILE) = COUNT' - Prefer 'test_line_count = 0 FILE' over 'cmp -s /dev/null FILE' - Use '<<-EOF' style for here documents, so that they can be indented as well. Bot don't do that in case the resulting lines would be too long. Also when there is no $variable_substitution in the body of a here document, quote \EOF. - Don't redirect the output of commands to /dev/null unconditionally, the git testing framework should already take care of handling test verbosity transparently and uniformly. Signed-off-by: Stefano Lattarini <stefano.lattarini@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefano Lattarini committed Mar 2, 2012 at 10:08 UTC 1b5b2b641adb1735086a58f4a77c72ba34c87231
1 file changed +289 -274
t/t0000-basic.sh
+289 -274
@@ -34,69 +34,69 @@ fi
34 # git init has been done in an empty repository.
35 # make sure it is empty.
36
37 -find .git/objects -type f -print >should-be-empty
38 -test_expect_success \
39 - '.git/objects should be empty after git init in an empty repo.' \
40 - 'cmp -s /dev/null should-be-empty'
37 +test_expect_success '.git/objects should be empty after git init in an empty repo' '
38 + find .git/objects -type f -print >should-be-empty &&
39 + test_line_count = 0 should-be-empty
40 +'
41
42 # also it should have 2 subdirectories; no fan-out anymore, pack, and info.
43 # 3 is counting "objects" itself
44 -find .git/objects -type d -print >full-of-directories
45 -test_expect_success \
46 - '.git/objects should have 3 subdirectories.' \
47 - 'test $(wc -l < full-of-directories) = 3'
44 +test_expect_success '.git/objects should have 3 subdirectories' '
45 + find .git/objects -type d -print >full-of-directories &&
46 + test_line_count = 3 full-of-directories
47 +'
48
49 ################################################################
50 # Test harness
51 test_expect_success 'success is reported like this' '
52 - :
52 + :
53 '
54 test_expect_failure 'pretend we have a known breakage' '
55 - false
55 + false
56 '
57
58 test_expect_success 'pretend we have fixed a known breakage (run in sub test-lib)' "
59 - mkdir passing-todo &&
60 - (cd passing-todo &&
61 - cat >passing-todo.sh <<EOF &&
62 -#!$SHELL_PATH
63 -
64 -test_description='A passing TODO test
65 -
66 -This is run in a sub test-lib so that we do not get incorrect passing
67 -metrics
68 -'
69 -
70 -# Point to the t/test-lib.sh, which isn't in ../ as usual
71 -TEST_DIRECTORY=\"$TEST_DIRECTORY\"
72 -. \"\$TEST_DIRECTORY\"/test-lib.sh
73 -
74 -test_expect_failure 'pretend we have fixed a known breakage' '
75 - :
76 -'
77 -
78 -test_done
79 -EOF
80 - chmod +x passing-todo.sh &&
81 - ./passing-todo.sh >out 2>err &&
82 - ! test -s err &&
83 -sed -e 's/^> //' >expect <<EOF &&
84 -> ok 1 - pretend we have fixed a known breakage # TODO known breakage
85 -> # fixed 1 known breakage(s)
86 -> # passed all 1 test(s)
87 -> 1..1
88 -EOF
89 - test_cmp expect out)
59 + mkdir passing-todo &&
60 + (cd passing-todo &&
61 + cat >passing-todo.sh <<-EOF &&
62 + #!$SHELL_PATH
63 +
64 + test_description='A passing TODO test
65 +
66 + This is run in a sub test-lib so that we do not get incorrect
67 + passing metrics
68 + '
69 +
70 + # Point to the t/test-lib.sh, which isn't in ../ as usual
71 + TEST_DIRECTORY=\"$TEST_DIRECTORY\"
72 + . \"\$TEST_DIRECTORY\"/test-lib.sh
73 +
74 + test_expect_failure 'pretend we have fixed a known breakage' '
75 + :
76 + '
77 +
78 + test_done
79 + EOF
80 + chmod +x passing-todo.sh &&
81 + ./passing-todo.sh >out 2>err &&
82 + ! test -s err &&
83 + sed -e 's/^> //' >expect <<-\\EOF &&
84 + > ok 1 - pretend we have fixed a known breakage # TODO known breakage
85 + > # fixed 1 known breakage(s)
86 + > # passed all 1 test(s)
87 + > 1..1
88 + EOF
89 + test_cmp expect out)
90 "
91 test_set_prereq HAVEIT
92 haveit=no
93 test_expect_success HAVEIT 'test runs if prerequisite is satisfied' '
94 - test_have_prereq HAVEIT &&
95 - haveit=yes
94 + test_have_prereq HAVEIT &&
95 + haveit=yes
96 '
97 donthaveit=yes
98 test_expect_success DONTHAVEIT 'unmet prerequisite causes test to be skipped' '
99 - donthaveit=no
99 + donthaveit=no
100 '
101 if test $haveit$donthaveit != yesyes
102 then
@@ -107,17 +107,17 @@ fi
107 test_set_prereq HAVETHIS
108 haveit=no
109 test_expect_success HAVETHIS,HAVEIT 'test runs if prerequisites are satisfied' '
110 - test_have_prereq HAVEIT &&
111 - test_have_prereq HAVETHIS &&
112 - haveit=yes
110 + test_have_prereq HAVEIT &&
111 + test_have_prereq HAVETHIS &&
112 + haveit=yes
113 '
114 donthaveit=yes
115 test_expect_success HAVEIT,DONTHAVEIT 'unmet prerequisites causes test to be skipped' '
116 - donthaveit=no
116 + donthaveit=no
117 '
118 donthaveiteither=yes
119 test_expect_success DONTHAVEIT,HAVEIT 'unmet prerequisites causes test to be skipped' '
120 - donthaveiteither=no
120 + donthaveiteither=no
121 '
122 if test $haveit$donthaveit$donthaveiteither != yesyesyes
123 then
@@ -127,7 +127,7 @@ fi
127
128 clean=no
129 test_expect_success 'tests clean up after themselves' '
130 - test_when_finished clean=yes
130 + test_when_finished clean=yes
131 '
132
133 if test $clean != yes
@@ -137,106 +137,100 @@ then
137 fi
138
139 test_expect_success 'tests clean up even on failures' "
140 - mkdir failing-cleanup &&
141 - (cd failing-cleanup &&
142 - cat >failing-cleanup.sh <<EOF &&
143 -#!$SHELL_PATH
144 -
145 -test_description='Failing tests with cleanup commands'
146 -
147 -# Point to the t/test-lib.sh, which isn't in ../ as usual
148 -TEST_DIRECTORY=\"$TEST_DIRECTORY\"
149 -. \"\$TEST_DIRECTORY\"/test-lib.sh
150 -
151 -test_expect_success 'tests clean up even after a failure' '
152 - touch clean-after-failure &&
153 - test_when_finished rm clean-after-failure &&
154 - (exit 1)
155 -'
156 -
157 -test_expect_success 'failure to clean up causes the test to fail' '
158 - test_when_finished \"(exit 2)\"
159 -'
160 -
161 -test_done
162 -EOF
163 - chmod +x failing-cleanup.sh &&
164 - test_must_fail ./failing-cleanup.sh >out 2>err &&
165 - ! test -s err &&
166 - ! test -f \"trash directory.failing-cleanup/clean-after-failure\" &&
167 -sed -e 's/Z$//' -e 's/^> //' >expect <<\EOF &&
168 -> not ok - 1 tests clean up even after a failure
169 -> # Z
170 -> # touch clean-after-failure &&
171 -> # test_when_finished rm clean-after-failure &&
172 -> # (exit 1)
173 -> # Z
174 -> not ok - 2 failure to clean up causes the test to fail
175 -> # Z
176 -> # test_when_finished \"(exit 2)\"
177 -> # Z
178 -> # failed 2 among 2 test(s)
179 -> 1..2
180 -EOF
181 - test_cmp expect out)
140 + mkdir failing-cleanup &&
141 + (
142 + cd failing-cleanup &&
143 +
144 + cat >failing-cleanup.sh <<-EOF &&
145 + #!$SHELL_PATH
146 +
147 + test_description='Failing tests with cleanup commands'
148 +
149 + # Point to the t/test-lib.sh, which isn't in ../ as usual
150 + TEST_DIRECTORY=\"$TEST_DIRECTORY\"
151 + . \"\$TEST_DIRECTORY\"/test-lib.sh
152 +
153 + test_expect_success 'tests clean up even after a failure' '
154 + touch clean-after-failure &&
155 + test_when_finished rm clean-after-failure &&
156 + (exit 1)
157 + '
158 + test_expect_success 'failure to clean up causes the test to fail' '
159 + test_when_finished \"(exit 2)\"
160 + '
161 + test_done
162 +
163 + EOF
164 +
165 + chmod +x failing-cleanup.sh &&
166 + test_must_fail ./failing-cleanup.sh >out 2>err &&
167 + ! test -s err &&
168 + ! test -f \"trash directory.failing-cleanup/clean-after-failure\" &&
169 + sed -e 's/Z$//' -e 's/^> //' >expect <<-\\EOF &&
170 + > not ok - 1 tests clean up even after a failure
171 + > # Z
172 + > # touch clean-after-failure &&
173 + > # test_when_finished rm clean-after-failure &&
174 + > # (exit 1)
175 + > # Z
176 + > not ok - 2 failure to clean up causes the test to fail
177 + > # Z
178 + > # test_when_finished \"(exit 2)\"
179 + > # Z
180 + > # failed 2 among 2 test(s)
181 + > 1..2
182 + EOF
183 + test_cmp expect out
184 + )
185 "
186
187 ################################################################
188 # Basics of the basics
189
190 # updating a new file without --add should fail.
188 -test_expect_success 'git update-index without --add should fail adding.' '
189 - test_must_fail git update-index should-be-empty
191 +test_expect_success 'git update-index without --add should fail adding' '
192 + test_must_fail git update-index should-be-empty
193 '
194
195 # and with --add it should succeed, even if it is empty (it used to fail).
193 -test_expect_success \
194 - 'git update-index with --add should succeed.' \
195 - 'git update-index --add should-be-empty'
196 +test_expect_success 'git update-index with --add should succeed' '
197 + git update-index --add should-be-empty
198 +'
199
197 -test_expect_success \
198 - 'writing tree out with git write-tree' \
199 - 'tree=$(git write-tree)'
200 +test_expect_success 'writing tree out with git write-tree' '
201 + tree=$(git write-tree)
202 +'
203
204 # we know the shape and contents of the tree and know the object ID for it.
202 -test_expect_success \
203 - 'validate object ID of a known tree.' \
204 - 'test "$tree" = 7bb943559a305bdd6bdee2cef6e5df2413c3d30a'
205 +test_expect_success 'validate object ID of a known tree' '
206 + test "$tree" = 7bb943559a305bdd6bdee2cef6e5df2413c3d30a
207 + '
208
209 # Removing paths.
207 -rm -f should-be-empty full-of-directories
208 -test_expect_success 'git update-index without --remove should fail removing.' '
209 - test_must_fail git update-index should-be-empty
210 +test_expect_success 'git update-index without --remove should fail removing' '
211 + rm -f should-be-empty full-of-directories &&
212 + test_must_fail git update-index should-be-empty
213 '
214
212 -test_expect_success \
213 - 'git update-index with --remove should be able to remove.' \
214 - 'git update-index --remove should-be-empty'
215 +test_expect_success 'git update-index with --remove should be able to remove' '
216 + git update-index --remove should-be-empty
217 +'
218
219 # Empty tree can be written with recent write-tree.
217 -test_expect_success \
218 - 'git write-tree should be able to write an empty tree.' \
219 - 'tree=$(git write-tree)'
220 +test_expect_success 'git write-tree should be able to write an empty tree' '
221 + tree=$(git write-tree)
222 +'
223
221 -test_expect_success \
222 - 'validate object ID of a known tree.' \
223 - 'test "$tree" = 4b825dc642cb6eb9a060e54bf8d69288fbee4904'
224 +test_expect_success 'validate object ID of a known tree' '
225 + test "$tree" = 4b825dc642cb6eb9a060e54bf8d69288fbee4904
226 +'
227
228 # Various types of objects
229 +
230 # Some filesystems do not support symblic links; on such systems
231 # some expected values are different
228 -mkdir path2 path3 path3/subp3
229 -paths='path0 path2/file2 path3/file3 path3/subp3/file3'
230 -for p in $paths
231 -do
232 - echo "hello $p" >$p
233 -done
232 if test_have_prereq SYMLINKS
233 then
236 - for p in $paths
237 - do
238 - ln -s "hello $p" ${p}sym
239 - done
234 expectfilter=cat
235 expectedtree=087704a96baf1c2d1c869a8b084481e121c88b5b
236 expectedptree1=21ae8269cacbe57ae09138dcc3a2887f904d02b3
@@ -248,135 +242,154 @@ else
242 expectedptree2=ce580448f0148b985a513b693fdf7d802cacb44f
243 fi
244
251 -test_expect_success \
252 - 'adding various types of objects with git update-index --add.' \
253 - 'find path* ! -type d -print | xargs git update-index --add'
245 +
246 +test_expect_success 'adding various types of objects with git update-index --add' '
247 + mkdir path2 path3 path3/subp3 &&
248 + paths="path0 path2/file2 path3/file3 path3/subp3/file3" &&
249 + (
250 + for p in $paths
251 + do
252 + echo "hello $p" >$p || exit 1
253 + if test_have_prereq SYMLINKS
254 + then
255 + ln -s "hello $p" ${p}sym || exit 1
256 + fi
257 + done
258 + ) &&
259 + find path* ! -type d -print | xargs git update-index --add
260 +'
261
262 # Show them and see that matches what we expect.
256 -test_expect_success \
257 - 'showing stage with git ls-files --stage' \
258 - 'git ls-files --stage >current'
259 -
260 -$expectfilter >expected <<\EOF
261 -100644 f87290f8eb2cbbea7857214459a0739927eab154 0 path0
262 -120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0 path0sym
263 -100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0 path2/file2
264 -120000 d8ce161addc5173867a3c3c730924388daedbc38 0 path2/file2sym
265 -100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0 path3/file3
266 -120000 8599103969b43aff7e430efea79ca4636466794f 0 path3/file3sym
267 -100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0 path3/subp3/file3
268 -120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0 path3/subp3/file3sym
269 -EOF
270 -test_expect_success \
271 - 'validate git ls-files output for a known tree.' \
272 - 'test_cmp expected current'
273 -
274 -test_expect_success \
275 - 'writing tree out with git write-tree.' \
276 - 'tree=$(git write-tree)'
277 -test_expect_success \
278 - 'validate object ID for a known tree.' \
279 - 'test "$tree" = "$expectedtree"'
280 -
281 -test_expect_success \
282 - 'showing tree with git ls-tree' \
283 - 'git ls-tree $tree >current'
284 -cat >expected <<\EOF
285 -100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
286 -120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
287 -040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2
288 -040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
289 -EOF
290 -test_expect_success SYMLINKS \
291 - 'git ls-tree output for a known tree.' \
292 - 'test_cmp expected current'
263 +test_expect_success 'showing stage with git ls-files --stage' '
264 + git ls-files --stage >current
265 +'
266 +
267 +test_expect_success 'validate git ls-files output for a known tree' '
268 + $expectfilter >expected <<-\EOF &&
269 + 100644 f87290f8eb2cbbea7857214459a0739927eab154 0 path0
270 + 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0 path0sym
271 + 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0 path2/file2
272 + 120000 d8ce161addc5173867a3c3c730924388daedbc38 0 path2/file2sym
273 + 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0 path3/file3
274 + 120000 8599103969b43aff7e430efea79ca4636466794f 0 path3/file3sym
275 + 100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0 path3/subp3/file3
276 + 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0 path3/subp3/file3sym
277 + EOF
278 + test_cmp expected current
279 +'
280 +
281 +test_expect_success 'writing tree out with git write-tree' '
282 + tree=$(git write-tree)
283 +'
284 +
285 +test_expect_success 'validate object ID for a known tree' '
286 + test "$tree" = "$expectedtree"
287 +'
288 +
289 +test_expect_success 'showing tree with git ls-tree' '
290 + git ls-tree $tree >current
291 +'
292 +
293 +test_expect_success SYMLINKS 'git ls-tree output for a known tree' '
294 + cat >expected <<-\EOF &&
295 + 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
296 + 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
297 + 040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2
298 + 040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
299 + EOF
300 + test_cmp expected current
301 +'
302
303 # This changed in ls-tree pathspec change -- recursive does
304 # not show tree nodes anymore.
296 -test_expect_success \
297 - 'showing tree with git ls-tree -r' \
298 - 'git ls-tree -r $tree >current'
299 -$expectfilter >expected <<\EOF
300 -100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
301 -120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
302 -100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2
303 -120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym
304 -100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3
305 -120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym
306 -100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3
307 -120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym
308 -EOF
309 -test_expect_success \
310 - 'git ls-tree -r output for a known tree.' \
311 - 'test_cmp expected current'
305 +test_expect_success 'showing tree with git ls-tree -r' '
306 + git ls-tree -r $tree >current
307 +'
308 +
309 +test_expect_success 'git ls-tree -r output for a known tree' '
310 + $expectfilter >expected <<-\EOF &&
311 + 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
312 + 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
313 + 100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2
314 + 120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym
315 + 100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3
316 + 120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym
317 + 100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3
318 + 120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym
319 + EOF
320 + test_cmp expected current
321 +'
322
323 # But with -r -t we can have both.
314 -test_expect_success \
315 - 'showing tree with git ls-tree -r -t' \
316 - 'git ls-tree -r -t $tree >current'
317 -cat >expected <<\EOF
318 -100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
319 -120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
320 -040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2
321 -100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2
322 -120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym
323 -040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
324 -100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3
325 -120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym
326 -040000 tree 3c5e5399f3a333eddecce7a9b9465b63f65f51e2 path3/subp3
327 -100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3
328 -120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym
329 -EOF
330 -test_expect_success SYMLINKS \
331 - 'git ls-tree -r output for a known tree.' \
332 - 'test_cmp expected current'
333 -
334 -test_expect_success \
335 - 'writing partial tree out with git write-tree --prefix.' \
336 - 'ptree=$(git write-tree --prefix=path3)'
337 -test_expect_success \
338 - 'validate object ID for a known tree.' \
339 - 'test "$ptree" = "$expectedptree1"'
340 -
341 -test_expect_success \
342 - 'writing partial tree out with git write-tree --prefix.' \
343 - 'ptree=$(git write-tree --prefix=path3/subp3)'
344 -test_expect_success \
345 - 'validate object ID for a known tree.' \
346 - 'test "$ptree" = "$expectedptree2"'
347 -
348 -cat >badobjects <<EOF
349 -100644 blob 1000000000000000000000000000000000000000 dir/file1
350 -100644 blob 2000000000000000000000000000000000000000 dir/file2
351 -100644 blob 3000000000000000000000000000000000000000 dir/file3
352 -100644 blob 4000000000000000000000000000000000000000 dir/file4
353 -100644 blob 5000000000000000000000000000000000000000 dir/file5
354 -EOF
324 +test_expect_success 'showing tree with git ls-tree -r -t' '
325 + git ls-tree -r -t $tree >current
326 +'
327
356 -rm .git/index
357 -test_expect_success \
358 - 'put invalid objects into the index.' \
359 - 'git update-index --index-info < badobjects'
328 +test_expect_success SYMLINKS 'git ls-tree -r output for a known tree' '
329 + cat >expected <<-\EOF &&
330 + 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
331 + 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
332 + 040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2
333 + 100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2
334 + 120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym
335 + 040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
336 + 100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3
337 + 120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym
338 + 040000 tree 3c5e5399f3a333eddecce7a9b9465b63f65f51e2 path3/subp3
339 + 100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3
340 + 120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym
341 + EOF
342 + test_cmp expected current
343 +'
344
361 -test_expect_success 'writing this tree without --missing-ok.' '
362 - test_must_fail git write-tree
345 +test_expect_success 'writing partial tree out with git write-tree --prefix' '
346 + ptree=$(git write-tree --prefix=path3)
347 '
348
365 -test_expect_success \
366 - 'writing this tree with --missing-ok.' \
367 - 'git write-tree --missing-ok'
349 +test_expect_success 'validate object ID for a known tree' '
350 + test "$ptree" = "$expectedptree1"
351 +'
352 +
353 +test_expect_success 'writing partial tree out with git write-tree --prefix' '
354 + ptree=$(git write-tree --prefix=path3/subp3)
355 +'
356 +
357 +test_expect_success 'validate object ID for a known tree' '
358 + test "$ptree" = "$expectedptree2"
359 +'
360 +
361 +test_expect_success 'put invalid objects into the index' '
362 + rm -f .git/index &&
363 + cat >badobjects <<-\EOF &&
364 + 100644 blob 1000000000000000000000000000000000000000 dir/file1
365 + 100644 blob 2000000000000000000000000000000000000000 dir/file2
366 + 100644 blob 3000000000000000000000000000000000000000 dir/file3
367 + 100644 blob 4000000000000000000000000000000000000000 dir/file4
368 + 100644 blob 5000000000000000000000000000000000000000 dir/file5
369 + EOF
370 + git update-index --index-info <badobjects
371 +'
372 +
373 +test_expect_success 'writing this tree without --missing-ok' '
374 + test_must_fail git write-tree
375 +'
376 +
377 +test_expect_success 'writing this tree with --missing-ok' '
378 + git write-tree --missing-ok
379 +'
380
381
382 ################################################################
371 -rm .git/index
372 -test_expect_success \
373 - 'git read-tree followed by write-tree should be idempotent.' \
374 - 'git read-tree $tree &&
375 - test -f .git/index &&
376 - newtree=$(git write-tree) &&
377 - test "$newtree" = "$tree"'
378 -
379 -$expectfilter >expected <<\EOF
383 +test_expect_success 'git read-tree followed by write-tree should be idempotent' '
384 + rm -f .git/index
385 + git read-tree $tree &&
386 + test -f .git/index &&
387 + newtree=$(git write-tree) &&
388 + test "$newtree" = "$tree"
389 +'
390 +
391 +test_expect_success 'validate git diff-files output for a know cache/work tree state' '
392 + $expectfilter >expected <<\EOF &&
393 :100644 100644 f87290f8eb2cbbea7857214459a0739927eab154 0000000000000000000000000000000000000000 M path0
394 :120000 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0000000000000000000000000000000000000000 M path0sym
395 :100644 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0000000000000000000000000000000000000000 M path2/file2
@@ -386,45 +399,47 @@ $expectfilter >expected <<\EOF
399 :100644 100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0000000000000000000000000000000000000000 M path3/subp3/file3
400 :120000 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0000000000000000000000000000000000000000 M path3/subp3/file3sym
401 EOF
389 -test_expect_success \
390 - 'validate git diff-files output for a know cache/work tree state.' \
391 - 'git diff-files >current && test_cmp current expected >/dev/null'
402 + git diff-files >current &&
403 + test_cmp current expected
404 +'
405
393 -test_expect_success \
394 - 'git update-index --refresh should succeed.' \
395 - 'git update-index --refresh'
406 +test_expect_success 'git update-index --refresh should succeed' '
407 + git update-index --refresh
408 +'
409
397 -test_expect_success \
398 - 'no diff after checkout and git update-index --refresh.' \
399 - 'git diff-files >current && cmp -s current /dev/null'
410 +test_expect_success 'no diff after checkout and git update-index --refresh' '
411 + git diff-files >current &&
412 + cmp -s current /dev/null
413 +'
414
415 ################################################################
416 P=$expectedtree
403 -test_expect_success \
404 - 'git commit-tree records the correct tree in a commit.' \
405 - 'commit0=$(echo NO | git commit-tree $P) &&
406 - tree=$(git show --pretty=raw $commit0 |
407 - sed -n -e "s/^tree //p" -e "/^author /q") &&
408 - test "z$tree" = "z$P"'
409 -
410 -test_expect_success \
411 - 'git commit-tree records the correct parent in a commit.' \
412 - 'commit1=$(echo NO | git commit-tree $P -p $commit0) &&
413 - parent=$(git show --pretty=raw $commit1 |
414 - sed -n -e "s/^parent //p" -e "/^author /q") &&
415 - test "z$commit0" = "z$parent"'
416 -
417 -test_expect_success \
418 - 'git commit-tree omits duplicated parent in a commit.' \
419 - 'commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) &&
420 - parent=$(git show --pretty=raw $commit2 |
421 - sed -n -e "s/^parent //p" -e "/^author /q" |
422 - sort -u) &&
423 - test "z$commit0" = "z$parent" &&
424 - numparent=$(git show --pretty=raw $commit2 |
425 - sed -n -e "s/^parent //p" -e "/^author /q" |
426 - wc -l) &&
427 - test $numparent = 1'
417 +
418 +test_expect_success 'git commit-tree records the correct tree in a commit' '
419 + commit0=$(echo NO | git commit-tree $P) &&
420 + tree=$(git show --pretty=raw $commit0 |
421 + sed -n -e "s/^tree //p" -e "/^author /q") &&
422 + test "z$tree" = "z$P"
423 +'
424 +
425 +test_expect_success 'git commit-tree records the correct parent in a commit' '
426 + commit1=$(echo NO | git commit-tree $P -p $commit0) &&
427 + parent=$(git show --pretty=raw $commit1 |
428 + sed -n -e "s/^parent //p" -e "/^author /q") &&
429 + test "z$commit0" = "z$parent"
430 +'
431 +
432 +test_expect_success 'git commit-tree omits duplicated parent in a commit' '
433 + commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) &&
434 + parent=$(git show --pretty=raw $commit2 |
435 + sed -n -e "s/^parent //p" -e "/^author /q" |
436 + sort -u) &&
437 + test "z$commit0" = "z$parent" &&
438 + numparent=$(git show --pretty=raw $commit2 |
439 + sed -n -e "s/^parent //p" -e "/^author /q" |
440 + wc -l) &&
441 + test $numparent = 1
442 +'
443
444 test_expect_success 'update-index D/F conflict' '
445 mv path0 tmp &&