]> git.ipfire.org Git - thirdparty/git.git/blame - t/t0000-basic.sh
Documentation/git-clone: describe --mirror more verbosely
[thirdparty/git.git] / t / t0000-basic.sh
CommitLineData
e1970ce4
JH
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
6test_description='Test the very basics part #1.
7
8The rest of the test suite does not check the basic operation of git
9plumbing commands to work very carefully. Their job is to concentrate
10on tricky features that caused bugs in the past to detect regression.
11
12This test runs very basic features, like registering things in cache,
13writing tree, etc.
14
15Note that this test *deliberately* hard-codes many expected object
16IDs. When object ID computation changes, like in the previous case of
17swapping compression and hashing order, the person who is making the
18modification *should* take notice and update the test vectors here.
19'
eea42069
JH
20
21################################################################
e2b70087 22# It appears that people try to run tests without building...
eea42069
JH
23
24../git >/dev/null
25if test $? != 1
26then
27 echo >&2 'You do not seem to have built git yet.'
28 exit 1
29fi
30
e1970ce4
JH
31. ./test-lib.sh
32
33################################################################
5be60078 34# git init has been done in an empty repository.
e1970ce4
JH
35# make sure it is empty.
36
37find .git/objects -type f -print >should-be-empty
38test_expect_success \
5be60078 39 '.git/objects should be empty after git init in an empty repo.' \
a6080a0a 40 'cmp -s /dev/null should-be-empty'
e1970ce4 41
9106c097
LT
42# also it should have 2 subdirectories; no fan-out anymore, pack, and info.
43# 3 is counting "objects" itself
e1970ce4
JH
44find .git/objects -type d -print >full-of-directories
45test_expect_success \
9106c097
LT
46 '.git/objects should have 3 subdirectories.' \
47 'test $(wc -l < full-of-directories) = 3'
e1970ce4 48
41ac414e
JH
49################################################################
50# Test harness
51test_expect_success 'success is reported like this' '
52 :
53'
54test_expect_failure 'pretend we have a known breakage' '
55 false
56'
7b905119
ÆAB
57
58test_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
64test_description='A passing TODO test
65
66This is run in a sub test-lib so that we do not get incorrect passing
67metrics
68'
69
70# Point to the t/test-lib.sh, which isn't in ../ as usual
71TEST_DIRECTORY=\"$TEST_DIRECTORY\"
72. \"\$TEST_DIRECTORY\"/test-lib.sh
73
41ac414e
JH
74test_expect_failure 'pretend we have fixed a known breakage' '
75 :
76'
7b905119
ÆAB
77
78test_done
79EOF
80 chmod +x passing-todo.sh &&
81 ./passing-todo.sh >out 2>err &&
82 ! test -s err &&
83cat >expect <<EOF &&
84ok 1 - pretend we have fixed a known breakage # TODO known breakage
85# fixed 1 known breakage(s)
86# passed all 1 test(s)
871..1
88EOF
89 test_cmp expect out)
90"
a7bb3940
JS
91test_set_prereq HAVEIT
92haveit=no
93test_expect_success HAVEIT 'test runs if prerequisite is satisfied' '
94 test_have_prereq HAVEIT &&
95 haveit=yes
96'
97donthaveit=yes
98test_expect_success DONTHAVEIT 'unmet prerequisite causes test to be skipped' '
99 donthaveit=no
100'
101if test $haveit$donthaveit != yesyes
102then
103 say "bug in test framework: prerequisite tags do not work reliably"
93a57246
ÆAB
104 exit 1
105fi
106
107test_set_prereq HAVETHIS
108haveit=no
109test_expect_success HAVETHIS,HAVEIT 'test runs if prerequisites are satisfied' '
110 test_have_prereq HAVEIT &&
111 test_have_prereq HAVETHIS &&
112 haveit=yes
113'
114donthaveit=yes
115test_expect_success HAVEIT,DONTHAVEIT 'unmet prerequisites causes test to be skipped' '
116 donthaveit=no
117'
ce60653e
ÆAB
118donthaveiteither=yes
119test_expect_success DONTHAVEIT,HAVEIT 'unmet prerequisites causes test to be skipped' '
120 donthaveiteither=no
121'
122if test $haveit$donthaveit$donthaveiteither != yesyesyes
93a57246
ÆAB
123then
124 say "bug in test framework: multiple prerequisite tags do not work reliably"
a7bb3940
JS
125 exit 1
126fi
41ac414e 127
b6b0afdc
JN
128clean=no
129test_expect_success 'tests clean up after themselves' '
130 test_when_finished clean=yes
131'
132
133cleaner=no
134test_expect_code 1 'tests clean up even after a failure' '
135 test_when_finished cleaner=yes &&
136 (exit 1)
137'
138
139if test $clean$cleaner != yesyes
140then
141 say "bug in test framework: cleanup commands do not work reliably"
142 exit 1
143fi
144
145test_expect_code 2 'failure to clean up causes the test to fail' '
146 test_when_finished "(exit 2)"
147'
148
e1970ce4
JH
149################################################################
150# Basics of the basics
151
152# updating a new file without --add should fail.
41ac414e 153test_expect_success 'git update-index without --add should fail adding.' '
d492b31c 154 test_must_fail git update-index should-be-empty
41ac414e 155'
e1970ce4
JH
156
157# and with --add it should succeed, even if it is empty (it used to fail).
158test_expect_success \
5be60078
JH
159 'git update-index with --add should succeed.' \
160 'git update-index --add should-be-empty'
e1970ce4
JH
161
162test_expect_success \
5be60078
JH
163 'writing tree out with git write-tree' \
164 'tree=$(git write-tree)'
e1970ce4
JH
165
166# we know the shape and contents of the tree and know the object ID for it.
167test_expect_success \
168 'validate object ID of a known tree.' \
169 'test "$tree" = 7bb943559a305bdd6bdee2cef6e5df2413c3d30a'
170
171# Removing paths.
172rm -f should-be-empty full-of-directories
41ac414e 173test_expect_success 'git update-index without --remove should fail removing.' '
d492b31c 174 test_must_fail git update-index should-be-empty
41ac414e 175'
e1970ce4
JH
176
177test_expect_success \
5be60078
JH
178 'git update-index with --remove should be able to remove.' \
179 'git update-index --remove should-be-empty'
e1970ce4
JH
180
181# Empty tree can be written with recent write-tree.
182test_expect_success \
5be60078
JH
183 'git write-tree should be able to write an empty tree.' \
184 'tree=$(git write-tree)'
e1970ce4
JH
185
186test_expect_success \
187 'validate object ID of a known tree.' \
188 'test "$tree" = 4b825dc642cb6eb9a060e54bf8d69288fbee4904'
189
190# Various types of objects
704a3143
JS
191# Some filesystems do not support symblic links; on such systems
192# some expected values are different
e1970ce4 193mkdir path2 path3 path3/subp3
704a3143
JS
194paths='path0 path2/file2 path3/file3 path3/subp3/file3'
195for p in $paths
e1970ce4
JH
196do
197 echo "hello $p" >$p
e1970ce4 198done
704a3143
JS
199if test_have_prereq SYMLINKS
200then
201 for p in $paths
202 do
203 ln -s "hello $p" ${p}sym
204 done
205 expectfilter=cat
206 expectedtree=087704a96baf1c2d1c869a8b084481e121c88b5b
207 expectedptree1=21ae8269cacbe57ae09138dcc3a2887f904d02b3
208 expectedptree2=3c5e5399f3a333eddecce7a9b9465b63f65f51e2
209else
210 expectfilter='grep -v sym'
211 expectedtree=8e18edf7d7edcf4371a3ac6ae5f07c2641db7c46
212 expectedptree1=cfb8591b2f65de8b8cc1020cd7d9e67e7793b325
213 expectedptree2=ce580448f0148b985a513b693fdf7d802cacb44f
214fi
215
e1970ce4 216test_expect_success \
5be60078
JH
217 'adding various types of objects with git update-index --add.' \
218 'find path* ! -type d -print | xargs git update-index --add'
e1970ce4
JH
219
220# Show them and see that matches what we expect.
221test_expect_success \
5be60078
JH
222 'showing stage with git ls-files --stage' \
223 'git ls-files --stage >current'
e1970ce4 224
704a3143 225$expectfilter >expected <<\EOF
2eab945e
JH
226100644 f87290f8eb2cbbea7857214459a0739927eab154 0 path0
227120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0 path0sym
228100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0 path2/file2
229120000 d8ce161addc5173867a3c3c730924388daedbc38 0 path2/file2sym
230100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0 path3/file3
231120000 8599103969b43aff7e430efea79ca4636466794f 0 path3/file3sym
232100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0 path3/subp3/file3
233120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0 path3/subp3/file3sym
e1970ce4
JH
234EOF
235test_expect_success \
5be60078 236 'validate git ls-files output for a known tree.' \
188c3827 237 'test_cmp expected current'
e1970ce4
JH
238
239test_expect_success \
5be60078
JH
240 'writing tree out with git write-tree.' \
241 'tree=$(git write-tree)'
e1970ce4
JH
242test_expect_success \
243 'validate object ID for a known tree.' \
704a3143 244 'test "$tree" = "$expectedtree"'
e1970ce4
JH
245
246test_expect_success \
5be60078
JH
247 'showing tree with git ls-tree' \
248 'git ls-tree $tree >current'
e1970ce4 249cat >expected <<\EOF
2eab945e
JH
250100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
251120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
252040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2
253040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
e1970ce4 254EOF
704a3143 255test_expect_success SYMLINKS \
5be60078 256 'git ls-tree output for a known tree.' \
188c3827 257 'test_cmp expected current'
e1970ce4 258
246cc52f
JH
259# This changed in ls-tree pathspec change -- recursive does
260# not show tree nodes anymore.
e1970ce4 261test_expect_success \
5be60078
JH
262 'showing tree with git ls-tree -r' \
263 'git ls-tree -r $tree >current'
704a3143 264$expectfilter >expected <<\EOF
2eab945e
JH
265100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
266120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
2eab945e
JH
267100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2
268120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym
2eab945e
JH
269100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3
270120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym
2eab945e
JH
271100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3
272120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym
e1970ce4
JH
273EOF
274test_expect_success \
5be60078 275 'git ls-tree -r output for a known tree.' \
188c3827 276 'test_cmp expected current'
e1970ce4 277
fdeb6bf5
JH
278# But with -r -t we can have both.
279test_expect_success \
5be60078
JH
280 'showing tree with git ls-tree -r -t' \
281 'git ls-tree -r -t $tree >current'
fdeb6bf5
JH
282cat >expected <<\EOF
283100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
284120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
285040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2
286100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2
287120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym
288040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
289100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3
290120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym
291040000 tree 3c5e5399f3a333eddecce7a9b9465b63f65f51e2 path3/subp3
292100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3
293120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym
294EOF
704a3143 295test_expect_success SYMLINKS \
5be60078 296 'git ls-tree -r output for a known tree.' \
188c3827 297 'test_cmp expected current'
fdeb6bf5 298
6bd20358 299test_expect_success \
5be60078
JH
300 'writing partial tree out with git write-tree --prefix.' \
301 'ptree=$(git write-tree --prefix=path3)'
6bd20358
JH
302test_expect_success \
303 'validate object ID for a known tree.' \
704a3143 304 'test "$ptree" = "$expectedptree1"'
6bd20358
JH
305
306test_expect_success \
5be60078
JH
307 'writing partial tree out with git write-tree --prefix.' \
308 'ptree=$(git write-tree --prefix=path3/subp3)'
6bd20358
JH
309test_expect_success \
310 'validate object ID for a known tree.' \
704a3143 311 'test "$ptree" = "$expectedptree2"'
6bd20358 312
3d12d0cf
JS
313cat >badobjects <<EOF
314100644 blob 1000000000000000000000000000000000000000 dir/file1
315100644 blob 2000000000000000000000000000000000000000 dir/file2
316100644 blob 3000000000000000000000000000000000000000 dir/file3
317100644 blob 4000000000000000000000000000000000000000 dir/file4
318100644 blob 5000000000000000000000000000000000000000 dir/file5
319EOF
320
321rm .git/index
322test_expect_success \
323 'put invalid objects into the index.' \
5be60078 324 'git update-index --index-info < badobjects'
3d12d0cf 325
41ac414e 326test_expect_success 'writing this tree without --missing-ok.' '
d492b31c 327 test_must_fail git write-tree
41ac414e 328'
3d12d0cf
JS
329
330test_expect_success \
331 'writing this tree with --missing-ok.' \
5be60078 332 'git write-tree --missing-ok'
3d12d0cf
JS
333
334
e1970ce4
JH
335################################################################
336rm .git/index
337test_expect_success \
5be60078
JH
338 'git read-tree followed by write-tree should be idempotent.' \
339 'git read-tree $tree &&
e1970ce4 340 test -f .git/index &&
5be60078 341 newtree=$(git write-tree) &&
e1970ce4
JH
342 test "$newtree" = "$tree"'
343
704a3143 344$expectfilter >expected <<\EOF
b6d8f309
JH
345:100644 100644 f87290f8eb2cbbea7857214459a0739927eab154 0000000000000000000000000000000000000000 M path0
346:120000 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0000000000000000000000000000000000000000 M path0sym
347:100644 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0000000000000000000000000000000000000000 M path2/file2
348:120000 120000 d8ce161addc5173867a3c3c730924388daedbc38 0000000000000000000000000000000000000000 M path2/file2sym
349:100644 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0000000000000000000000000000000000000000 M path3/file3
350:120000 120000 8599103969b43aff7e430efea79ca4636466794f 0000000000000000000000000000000000000000 M path3/file3sym
351:100644 100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0000000000000000000000000000000000000000 M path3/subp3/file3
352:120000 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0000000000000000000000000000000000000000 M path3/subp3/file3sym
e1970ce4
JH
353EOF
354test_expect_success \
5be60078 355 'validate git diff-files output for a know cache/work tree state.' \
4fdf71be 356 'git diff-files >current && test_cmp current expected >/dev/null'
e1970ce4
JH
357
358test_expect_success \
5be60078
JH
359 'git update-index --refresh should succeed.' \
360 'git update-index --refresh'
e1970ce4
JH
361
362test_expect_success \
5be60078
JH
363 'no diff after checkout and git update-index --refresh.' \
364 'git diff-files >current && cmp -s current /dev/null'
e1970ce4 365
9af0b8db 366################################################################
704a3143 367P=$expectedtree
9af0b8db 368test_expect_success \
5be60078
JH
369 'git commit-tree records the correct tree in a commit.' \
370 'commit0=$(echo NO | git commit-tree $P) &&
9af0b8db
JH
371 tree=$(git show --pretty=raw $commit0 |
372 sed -n -e "s/^tree //p" -e "/^author /q") &&
373 test "z$tree" = "z$P"'
374
375test_expect_success \
5be60078
JH
376 'git commit-tree records the correct parent in a commit.' \
377 'commit1=$(echo NO | git commit-tree $P -p $commit0) &&
9af0b8db
JH
378 parent=$(git show --pretty=raw $commit1 |
379 sed -n -e "s/^parent //p" -e "/^author /q") &&
380 test "z$commit0" = "z$parent"'
381
382test_expect_success \
5be60078
JH
383 'git commit-tree omits duplicated parent in a commit.' \
384 'commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) &&
9af0b8db
JH
385 parent=$(git show --pretty=raw $commit2 |
386 sed -n -e "s/^parent //p" -e "/^author /q" |
387 sort -u) &&
388 test "z$commit0" = "z$parent" &&
389 numparent=$(git show --pretty=raw $commit2 |
390 sed -n -e "s/^parent //p" -e "/^author /q" |
391 wc -l) &&
392 test $numparent = 1'
393
81a361be
JH
394test_expect_success 'update-index D/F conflict' '
395 mv path0 tmp &&
396 mv path2 path0 &&
397 mv tmp path2 &&
398 git update-index --add --replace path2 path0/file2 &&
399 numpath0=$(git ls-files path0 | wc -l) &&
400 test $numpath0 = 1
401'
402
704a3143 403test_expect_success SYMLINKS 'absolute path works as expected' '
e5392c51
JS
404 mkdir first &&
405 ln -s ../.git first/.git &&
406 mkdir second &&
407 ln -s ../first second/other &&
408 mkdir third &&
409 dir="$(cd .git; pwd -P)" &&
410 dir2=third/../second/other/.git &&
d553e737 411 test "$dir" = "$(test-path-utils make_absolute_path $dir2)" &&
e5392c51 412 file="$dir"/index &&
d553e737 413 test "$file" = "$(test-path-utils make_absolute_path $dir2/index)" &&
e371a4c6 414 basename=blub &&
d553e737 415 test "$dir/$basename" = "$(cd .git && test-path-utils make_absolute_path "$basename")" &&
e5392c51
JS
416 ln -s ../first/file .git/syml &&
417 sym="$(cd first; pwd -P)"/file &&
d553e737 418 test "$sym" = "$(test-path-utils make_absolute_path "$dir2/syml")"
e5392c51
JS
419'
420
7fec10b7
JH
421test_expect_success 'very long name in the index handled sanely' '
422
423 a=a && # 1
424 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 16
425 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 256
426 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 4096
427 a=${a}q &&
428
429 >path4 &&
430 git update-index --add path4 &&
431 (
432 git ls-files -s path4 |
433 sed -e "s/ .*/ /" |
434 tr -d "\012"
435 echo "$a"
436 ) | git update-index --index-info &&
437 len=$(git ls-files "a*" | wc -c) &&
438 test $len = 4098
439'
440
e1970ce4 441test_done