3 # Copyright (c) 2005 Junio C Hamano
6 test_description
='Test the very basics part #1.
8 The rest of the test suite does not check the basic operation of git
9 plumbing commands to work very carefully. Their job is to concentrate
10 on tricky features that caused bugs in the past to detect regression.
12 This test runs very basic features, like registering things in cache,
15 Note that this test *deliberately* hard-codes many expected object
16 IDs. When object ID computation changes, like in the previous case of
17 swapping compression and hashing order, the person who is making the
18 modification *should* take notice and update the test vectors here.
21 ################################################################
22 # It appears that people try to run tests without building...
27 echo >&2 'You do not seem to have built git yet.'
33 test "$no_symlinks" && {
38 case "$1" in -*) opt
=$1; shift;; esac
39 tr -d "\015" < $1 > $1.doof
40 grep -v "^:\?120000" < $2 | \
41 sed -e s
/58a09c23e2ca152193f2786e06986b7b6712bdbe
/600f42758e4458c37c2c1f8063378f540b4efad
7/ \
42 -e s
/21ae8269cacbe57ae09138dcc3a2887f904d02b
3/cfb8591b2f65de8b8cc1020cd7d9e67e7793b325
/ \
43 -e s
/3c5e5399f3a333eddecce7a9b9465b63f65f51e
2/ce580448f0148b985a513b693fdf7d802cacb44f
/ \
45 $DIFF $opt $1.doof
$2.doof
49 ################################################################
50 # git init has been done in an empty repository.
51 # make sure it is empty.
53 find .git
/objects
-type f
-print >should-be-empty
55 '.git/objects should be empty after git init in an empty repo.' \
56 'cmp -s /dev/null should-be-empty'
58 # also it should have 2 subdirectories; no fan-out anymore, pack, and info.
59 # 3 is counting "objects" itself
60 find .git
/objects
-type d
-print >full-of-directories
62 '.git/objects should have 3 subdirectories.' \
63 'test $(wc -l < full-of-directories) = 3'
65 ################################################################
67 test_expect_success
'success is reported like this' '
70 test_expect_failure
'pretend we have a known breakage' '
73 test_expect_failure
'pretend we have fixed a known breakage' '
77 ################################################################
78 # Basics of the basics
80 # updating a new file without --add should fail.
81 test_expect_success
'git update-index without --add should fail adding.' '
82 ! git update-index should-be-empty
85 # and with --add it should succeed, even if it is empty (it used to fail).
87 'git update-index with --add should succeed.' \
88 'git update-index --add should-be-empty'
91 'writing tree out with git write-tree' \
92 'tree=$(git write-tree)'
94 # we know the shape and contents of the tree and know the object ID for it.
96 'validate object ID of a known tree.' \
97 'test "$tree" = 7bb943559a305bdd6bdee2cef6e5df2413c3d30a'
100 rm -f should-be-empty full-of-directories
101 test_expect_success
'git update-index without --remove should fail removing.' '
102 ! git update-index should-be-empty
105 test_expect_success \
106 'git update-index with --remove should be able to remove.' \
107 'git update-index --remove should-be-empty'
109 # Empty tree can be written with recent write-tree.
110 test_expect_success \
111 'git write-tree should be able to write an empty tree.' \
112 'tree=$(git write-tree)'
114 test_expect_success \
115 'validate object ID of a known tree.' \
116 'test "$tree" = 4b825dc642cb6eb9a060e54bf8d69288fbee4904'
118 # Various types of objects
119 mkdir path2 path3 path
3/subp3
120 for p
in path0 path
2/file2 path
3/file3 path
3/subp
3/file3
123 ln -s "hello $p" ${p}sym
125 test_expect_success \
126 'adding various types of objects with git update-index --add.' \
127 'find path* ! -type d -print | xargs git update-index --add'
129 # Show them and see that matches what we expect.
130 test_expect_success \
131 'showing stage with git ls-files --stage' \
132 'git ls-files --stage >current'
135 100644 f87290f8eb2cbbea7857214459a0739927eab154
0 path0
136 120000 15a98433ae33114b085f3eb3bb03b832b3180a01
0 path0sym
137 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7
0 path
2/file2
138 120000 d8ce161addc5173867a3c3c730924388daedbc38
0 path
2/file2sym
139 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376
0 path
3/file3
140 120000 8599103969b43aff7e430efea79ca4636466794f
0 path
3/file3sym
141 100644 00fb5908cb97c2564a9783c0c64087333b3b464f
0 path
3/subp
3/file3
142 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c
0 path
3/subp
3/file3sym
145 test_expect_success \
146 'validate git ls-files output for a known tree.' \
147 'diff current expected'
149 test_expect_success \
150 'writing tree out with git write-tree.' \
151 'tree=$(git write-tree)'
152 expected_tree
=087704a96baf1c2d1c869a8b084481e121c88b5b
153 test "$no_symlinks" && expected_tree
=8e18edf7d7edcf4371a3ac6ae5f07c2641db7c46
154 test_expect_success \
155 'validate object ID for a known tree.' \
156 'test "$tree" = "$expected_tree"'
158 test_expect_success \
159 'showing tree with git ls-tree' \
160 'git ls-tree $tree >current'
162 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
163 120000 blob
15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
164 040000 tree
58a09c23e2ca152193f2786e06986b7b6712bdbe path2
165 040000 tree
21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
167 test_expect_success \
168 'git ls-tree output for a known tree.' \
169 'diff current expected'
171 # This changed in ls-tree pathspec change -- recursive does
172 # not show tree nodes anymore.
173 test_expect_success \
174 'showing tree with git ls-tree -r' \
175 'git ls-tree -r $tree >current'
177 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
178 120000 blob
15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
179 100644 blob
3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path
2/file2
180 120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path
2/file2sym
181 100644 blob
0aa34cae68d0878578ad119c86ca2b5ed5b28376 path
3/file3
182 120000 blob
8599103969b43aff7e430efea79ca4636466794f path
3/file3sym
183 100644 blob
00fb5908cb97c2564a9783c0c64087333b3b464f path
3/subp
3/file3
184 120000 blob
6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path
3/subp
3/file3sym
186 test_expect_success \
187 'git ls-tree -r output for a known tree.' \
188 'diff current expected'
190 # But with -r -t we can have both.
191 test_expect_success \
192 'showing tree with git ls-tree -r -t' \
193 'git ls-tree -r -t $tree >current'
195 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
196 120000 blob
15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
197 040000 tree
58a09c23e2ca152193f2786e06986b7b6712bdbe path2
198 100644 blob
3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path
2/file2
199 120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path
2/file2sym
200 040000 tree
21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
201 100644 blob
0aa34cae68d0878578ad119c86ca2b5ed5b28376 path
3/file3
202 120000 blob
8599103969b43aff7e430efea79ca4636466794f path
3/file3sym
203 040000 tree
3c5e5399f3a333eddecce7a9b9465b63f65f51e2 path
3/subp3
204 100644 blob
00fb5908cb97c2564a9783c0c64087333b3b464f path
3/subp
3/file3
205 120000 blob
6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path
3/subp
3/file3sym
207 test_expect_success \
208 'git ls-tree -r output for a known tree.' \
209 'diff current expected'
211 test_expect_success \
212 'writing partial tree out with git write-tree --prefix.' \
213 'ptree=$(git write-tree --prefix=path3)'
214 expected_tree
=21ae8269cacbe57ae09138dcc3a2887f904d02b3
215 test "$no_symlinks" && expected_tree
=cfb8591b2f65de8b8cc1020cd7d9e67e7793b325
216 test_expect_success \
217 'validate object ID for a known tree.' \
218 'test "$ptree" = "$expected_tree"'
220 test_expect_success \
221 'writing partial tree out with git write-tree --prefix.' \
222 'ptree=$(git write-tree --prefix=path3/subp3)'
223 expect_tree
=3c5e5399f3a333eddecce7a9b9465b63f65f51e2
224 test "$no_symlinks" && expect_tree
=ce580448f0148b985a513b693fdf7d802cacb44f
225 test_expect_success \
226 'validate object ID for a known tree.' \
227 'test "$ptree" = "$expect_tree"'
229 cat >badobjects
<<EOF
230 100644 blob 1000000000000000000000000000000000000000 dir/file1
231 100644 blob 2000000000000000000000000000000000000000 dir/file2
232 100644 blob 3000000000000000000000000000000000000000 dir/file3
233 100644 blob 4000000000000000000000000000000000000000 dir/file4
234 100644 blob 5000000000000000000000000000000000000000 dir/file5
238 test_expect_success \
239 'put invalid objects into the index.' \
240 'git update-index --index-info < badobjects'
242 test_expect_success
'writing this tree without --missing-ok.' '
246 test_expect_success \
247 'writing this tree with --missing-ok.' \
248 'git write-tree --missing-ok'
251 ################################################################
253 test_expect_success \
254 'git read-tree followed by write-tree should be idempotent.' \
255 'git read-tree $tree &&
256 test -f .git/index &&
257 newtree=$(git write-tree) &&
258 test "$newtree" = "$tree"'
261 :100644 100644 f87290f8eb2cbbea7857214459a0739927eab154
0000000000000000000000000000000000000000 M path0
262 :120000 120000 15a98433ae33114b085f3eb3bb03b832b3180a01
0000000000000000000000000000000000000000 M path0sym
263 :100644 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7
0000000000000000000000000000000000000000 M path
2/file2
264 :120000 120000 d8ce161addc5173867a3c3c730924388daedbc38
0000000000000000000000000000000000000000 M path
2/file2sym
265 :100644 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376
0000000000000000000000000000000000000000 M path
3/file3
266 :120000 120000 8599103969b43aff7e430efea79ca4636466794f
0000000000000000000000000000000000000000 M path
3/file3sym
267 :100644 100644 00fb5908cb97c2564a9783c0c64087333b3b464f
0000000000000000000000000000000000000000 M path
3/subp
3/file3
268 :120000 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c
0000000000000000000000000000000000000000 M path
3/subp
3/file3sym
270 test_expect_success \
271 'validate git diff-files output for a know cache/work tree state.' \
272 'git diff-files >current && diff >/dev/null -b current expected'
274 test_expect_success \
275 'git update-index --refresh should succeed.' \
276 'git update-index --refresh'
278 test_expect_success \
279 'no diff after checkout and git update-index --refresh.' \
280 'git diff-files >current && cmp -s current /dev/null'
282 ################################################################
283 P
=087704a96baf1c2d1c869a8b084481e121c88b5b
284 test "$no_symlinks" && P
=7bb943559a305bdd6bdee2cef6e5df2413c3d30a
285 test_expect_success \
286 'git commit-tree records the correct tree in a commit.' \
287 'commit0=$(echo NO | git commit-tree $P) &&
288 tree=$(git show --pretty=raw $commit0 |
289 sed -n -e "s/^tree //p" -e "/^author /q") &&
290 test "z$tree" = "z$P"'
292 test_expect_success \
293 'git commit-tree records the correct parent in a commit.' \
294 'commit1=$(echo NO | git commit-tree $P -p $commit0) &&
295 parent=$(git show --pretty=raw $commit1 |
296 sed -n -e "s/^parent //p" -e "/^author /q") &&
297 test "z$commit0" = "z$parent"'
299 test_expect_success \
300 'git commit-tree omits duplicated parent in a commit.' \
301 'commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) &&
302 parent=$(git show --pretty=raw $commit2 |
303 sed -n -e "s/^parent //p" -e "/^author /q" |
305 test "z$commit0" = "z$parent" &&
306 numparent=$(git show --pretty=raw $commit2 |
307 sed -n -e "s/^parent //p" -e "/^author /q" |
311 test_expect_success
'update-index D/F conflict' '
315 git update-index --add --replace path2 path0/file2 &&
316 numpath0=$(git ls-files path0 | wc -l) &&
320 test "$no_symlinks" ||
321 test_expect_success
'absolute path works as expected' '
323 ln -s ../.git first/.git &&
325 ln -s ../first second/other &&
327 dir="$(cd .git; pwd -P)" &&
328 dir2=third/../second/other/.git &&
329 test "$dir" = "$(test-path-utils make_absolute_path $dir2)" &&
331 test "$file" = "$(test-path-utils make_absolute_path $dir2/index)" &&
333 test "$dir/$basename" = "$(cd .git && test-path-utils make_absolute_path "$basename")" &&
334 ln -s ../first/file .git/syml &&
335 sym="$(cd first; pwd -P)"/file &&
336 test "$sym" = "$(test-path-utils make_absolute_path "$dir2/syml")"
339 test_expect_success
'very long name in the index handled sanely' '
342 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 16
343 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 256
344 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 4096
348 git update-index --add path4 &&
350 git ls-files -s path4 |
354 ) | git update-index --index-info &&
355 len=$(git ls-files "a*" | wc -c) &&