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 ################################################################
34 # git init has been done in an empty repository.
35 # make sure it is empty.
37 find .git
/objects
-type f
-print >should-be-empty
39 '.git/objects should be empty after git init in an empty repo.' \
40 'cmp -s /dev/null should-be-empty'
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
46 '.git/objects should have 3 subdirectories.' \
47 'test $(wc -l < full-of-directories) = 3'
49 ################################################################
51 test_expect_success
'success is reported like this' '
54 test_expect_failure
'pretend we have a known breakage' '
57 test_expect_failure
'pretend we have fixed a known breakage' '
61 ################################################################
62 # Basics of the basics
64 # updating a new file without --add should fail.
65 test_expect_success
'git update-index without --add should fail adding.' '
66 test_must_fail git update-index should-be-empty
69 # and with --add it should succeed, even if it is empty (it used to fail).
71 'git update-index with --add should succeed.' \
72 'git update-index --add should-be-empty'
75 'writing tree out with git write-tree' \
76 'tree=$(git write-tree)'
78 # we know the shape and contents of the tree and know the object ID for it.
80 'validate object ID of a known tree.' \
81 'test "$tree" = 7bb943559a305bdd6bdee2cef6e5df2413c3d30a'
84 rm -f should-be-empty full-of-directories
85 test_expect_success
'git update-index without --remove should fail removing.' '
86 test_must_fail git update-index should-be-empty
90 'git update-index with --remove should be able to remove.' \
91 'git update-index --remove should-be-empty'
93 # Empty tree can be written with recent write-tree.
95 'git write-tree should be able to write an empty tree.' \
96 'tree=$(git write-tree)'
99 'validate object ID of a known tree.' \
100 'test "$tree" = 4b825dc642cb6eb9a060e54bf8d69288fbee4904'
102 # Various types of objects
103 # Some filesystems do not support symblic links; on such systems
104 # some expected values are different
105 mkdir path2 path3 path
3/subp3
106 paths
='path0 path2/file2 path3/file3 path3/subp3/file3'
111 if test -z "$no_symlinks"
115 ln -s "hello $p" ${p}sym
118 expectedtree
=087704a96baf1c2d1c869a8b084481e121c88b5b
119 expectedptree1
=21ae8269cacbe57ae09138dcc3a2887f904d02b3
120 expectedptree2
=3c5e5399f3a333eddecce7a9b9465b63f65f51e2
122 expectfilter
='grep -v sym'
123 expectedtree
=8e18edf7d7edcf4371a3ac6ae5f07c2641db7c46
124 expectedptree1
=cfb8591b2f65de8b8cc1020cd7d9e67e7793b325
125 expectedptree2
=ce580448f0148b985a513b693fdf7d802cacb44f
128 test_expect_success \
129 'adding various types of objects with git update-index --add.' \
130 'find path* ! -type d -print | xargs git update-index --add'
132 # Show them and see that matches what we expect.
133 test_expect_success \
134 'showing stage with git ls-files --stage' \
135 'git ls-files --stage >current'
137 $expectfilter >expected
<<\EOF
138 100644 f87290f8eb2cbbea7857214459a0739927eab154
0 path0
139 120000 15a98433ae33114b085f3eb3bb03b832b3180a01
0 path0sym
140 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7
0 path
2/file2
141 120000 d8ce161addc5173867a3c3c730924388daedbc38
0 path
2/file2sym
142 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376
0 path
3/file3
143 120000 8599103969b43aff7e430efea79ca4636466794f
0 path
3/file3sym
144 100644 00fb5908cb97c2564a9783c0c64087333b3b464f
0 path
3/subp
3/file3
145 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c
0 path
3/subp
3/file3sym
148 test_expect_success \
149 'validate git ls-files output for a known tree.' \
150 'test_cmp expected current'
152 test_expect_success \
153 'writing tree out with git write-tree.' \
154 'tree=$(git write-tree)'
155 test_expect_success \
156 'validate object ID for a known tree.' \
157 'test "$tree" = "$expectedtree"'
159 test_expect_success \
160 'showing tree with git ls-tree' \
161 'git ls-tree $tree >current'
163 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
164 120000 blob
15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
165 040000 tree
58a09c23e2ca152193f2786e06986b7b6712bdbe path2
166 040000 tree
21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
168 test -z "$no_symlinks" &&
169 test_expect_success \
170 'git ls-tree output for a known tree.' \
171 'test_cmp expected current'
173 # This changed in ls-tree pathspec change -- recursive does
174 # not show tree nodes anymore.
175 test_expect_success \
176 'showing tree with git ls-tree -r' \
177 'git ls-tree -r $tree >current'
178 $expectfilter >expected
<<\EOF
179 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
180 120000 blob
15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
181 100644 blob
3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path
2/file2
182 120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path
2/file2sym
183 100644 blob
0aa34cae68d0878578ad119c86ca2b5ed5b28376 path
3/file3
184 120000 blob
8599103969b43aff7e430efea79ca4636466794f path
3/file3sym
185 100644 blob
00fb5908cb97c2564a9783c0c64087333b3b464f path
3/subp
3/file3
186 120000 blob
6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path
3/subp
3/file3sym
188 test_expect_success \
189 'git ls-tree -r output for a known tree.' \
190 'test_cmp expected current'
192 # But with -r -t we can have both.
193 test_expect_success \
194 'showing tree with git ls-tree -r -t' \
195 'git ls-tree -r -t $tree >current'
197 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
198 120000 blob
15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
199 040000 tree
58a09c23e2ca152193f2786e06986b7b6712bdbe path2
200 100644 blob
3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path
2/file2
201 120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path
2/file2sym
202 040000 tree
21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
203 100644 blob
0aa34cae68d0878578ad119c86ca2b5ed5b28376 path
3/file3
204 120000 blob
8599103969b43aff7e430efea79ca4636466794f path
3/file3sym
205 040000 tree
3c5e5399f3a333eddecce7a9b9465b63f65f51e2 path
3/subp3
206 100644 blob
00fb5908cb97c2564a9783c0c64087333b3b464f path
3/subp
3/file3
207 120000 blob
6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path
3/subp
3/file3sym
209 test -z "$no_symlinks" &&
210 test_expect_success \
211 'git ls-tree -r output for a known tree.' \
212 'test_cmp expected current'
214 test_expect_success \
215 'writing partial tree out with git write-tree --prefix.' \
216 'ptree=$(git write-tree --prefix=path3)'
217 test_expect_success \
218 'validate object ID for a known tree.' \
219 'test "$ptree" = "$expectedptree1"'
221 test_expect_success \
222 'writing partial tree out with git write-tree --prefix.' \
223 'ptree=$(git write-tree --prefix=path3/subp3)'
224 test_expect_success \
225 'validate object ID for a known tree.' \
226 'test "$ptree" = "$expectedptree2"'
228 cat >badobjects
<<EOF
229 100644 blob 1000000000000000000000000000000000000000 dir/file1
230 100644 blob 2000000000000000000000000000000000000000 dir/file2
231 100644 blob 3000000000000000000000000000000000000000 dir/file3
232 100644 blob 4000000000000000000000000000000000000000 dir/file4
233 100644 blob 5000000000000000000000000000000000000000 dir/file5
237 test_expect_success \
238 'put invalid objects into the index.' \
239 'git update-index --index-info < badobjects'
241 test_expect_success
'writing this tree without --missing-ok.' '
242 test_must_fail git write-tree
245 test_expect_success \
246 'writing this tree with --missing-ok.' \
247 'git write-tree --missing-ok'
250 ################################################################
252 test_expect_success \
253 'git read-tree followed by write-tree should be idempotent.' \
254 'git read-tree $tree &&
255 test -f .git/index &&
256 newtree=$(git write-tree) &&
257 test "$newtree" = "$tree"'
259 $expectfilter >expected
<<\EOF
260 :100644 100644 f87290f8eb2cbbea7857214459a0739927eab154
0000000000000000000000000000000000000000 M path0
261 :120000 120000 15a98433ae33114b085f3eb3bb03b832b3180a01
0000000000000000000000000000000000000000 M path0sym
262 :100644 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7
0000000000000000000000000000000000000000 M path
2/file2
263 :120000 120000 d8ce161addc5173867a3c3c730924388daedbc38
0000000000000000000000000000000000000000 M path
2/file2sym
264 :100644 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376
0000000000000000000000000000000000000000 M path
3/file3
265 :120000 120000 8599103969b43aff7e430efea79ca4636466794f
0000000000000000000000000000000000000000 M path
3/file3sym
266 :100644 100644 00fb5908cb97c2564a9783c0c64087333b3b464f
0000000000000000000000000000000000000000 M path
3/subp
3/file3
267 :120000 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c
0000000000000000000000000000000000000000 M path
3/subp
3/file3sym
269 test_expect_success \
270 'validate git diff-files output for a know cache/work tree state.' \
271 'git diff-files >current && diff >/dev/null -b current expected'
273 test_expect_success \
274 'git update-index --refresh should succeed.' \
275 'git update-index --refresh'
277 test_expect_success \
278 'no diff after checkout and git update-index --refresh.' \
279 'git diff-files >current && cmp -s current /dev/null'
281 ################################################################
283 test_expect_success \
284 'git commit-tree records the correct tree in a commit.' \
285 'commit0=$(echo NO | git commit-tree $P) &&
286 tree=$(git show --pretty=raw $commit0 |
287 sed -n -e "s/^tree //p" -e "/^author /q") &&
288 test "z$tree" = "z$P"'
290 test_expect_success \
291 'git commit-tree records the correct parent in a commit.' \
292 'commit1=$(echo NO | git commit-tree $P -p $commit0) &&
293 parent=$(git show --pretty=raw $commit1 |
294 sed -n -e "s/^parent //p" -e "/^author /q") &&
295 test "z$commit0" = "z$parent"'
297 test_expect_success \
298 'git commit-tree omits duplicated parent in a commit.' \
299 'commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) &&
300 parent=$(git show --pretty=raw $commit2 |
301 sed -n -e "s/^parent //p" -e "/^author /q" |
303 test "z$commit0" = "z$parent" &&
304 numparent=$(git show --pretty=raw $commit2 |
305 sed -n -e "s/^parent //p" -e "/^author /q" |
309 test_expect_success
'update-index D/F conflict' '
313 git update-index --add --replace path2 path0/file2 &&
314 numpath0=$(git ls-files path0 | wc -l) &&
318 test -z "$no_symlinks" &&
319 test_expect_success
'absolute path works as expected' '
321 ln -s ../.git first/.git &&
323 ln -s ../first second/other &&
325 dir="$(cd .git; pwd -P)" &&
326 dir2=third/../second/other/.git &&
327 test "$dir" = "$(test-path-utils make_absolute_path $dir2)" &&
329 test "$file" = "$(test-path-utils make_absolute_path $dir2/index)" &&
331 test "$dir/$basename" = "$(cd .git && test-path-utils make_absolute_path "$basename")" &&
332 ln -s ../first/file .git/syml &&
333 sym="$(cd first; pwd -P)"/file &&
334 test "$sym" = "$(test-path-utils make_absolute_path "$dir2/syml")"
337 test_expect_success
'very long name in the index handled sanely' '
340 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 16
341 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 256
342 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 4096
346 git update-index --add path4 &&
348 git ls-files -s path4 |
352 ) | git update-index --index-info &&
353 len=$(git ls-files "a*" | wc -c) &&