]> git.ipfire.org Git - thirdparty/git.git/blame - t/t0000-basic.sh
Enhance hold_lock_file_for_{update,append}() API
[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'
57test_expect_failure 'pretend we have fixed a known breakage' '
58 :
59'
60
e1970ce4
JH
61################################################################
62# Basics of the basics
63
64# updating a new file without --add should fail.
41ac414e 65test_expect_success 'git update-index without --add should fail adding.' '
d492b31c 66 test_must_fail git update-index should-be-empty
41ac414e 67'
e1970ce4
JH
68
69# and with --add it should succeed, even if it is empty (it used to fail).
70test_expect_success \
5be60078
JH
71 'git update-index with --add should succeed.' \
72 'git update-index --add should-be-empty'
e1970ce4
JH
73
74test_expect_success \
5be60078
JH
75 'writing tree out with git write-tree' \
76 'tree=$(git write-tree)'
e1970ce4
JH
77
78# we know the shape and contents of the tree and know the object ID for it.
79test_expect_success \
80 'validate object ID of a known tree.' \
81 'test "$tree" = 7bb943559a305bdd6bdee2cef6e5df2413c3d30a'
82
83# Removing paths.
84rm -f should-be-empty full-of-directories
41ac414e 85test_expect_success 'git update-index without --remove should fail removing.' '
d492b31c 86 test_must_fail git update-index should-be-empty
41ac414e 87'
e1970ce4
JH
88
89test_expect_success \
5be60078
JH
90 'git update-index with --remove should be able to remove.' \
91 'git update-index --remove should-be-empty'
e1970ce4
JH
92
93# Empty tree can be written with recent write-tree.
94test_expect_success \
5be60078
JH
95 'git write-tree should be able to write an empty tree.' \
96 'tree=$(git write-tree)'
e1970ce4
JH
97
98test_expect_success \
99 'validate object ID of a known tree.' \
100 'test "$tree" = 4b825dc642cb6eb9a060e54bf8d69288fbee4904'
101
102# Various types of objects
103mkdir path2 path3 path3/subp3
104for p in path0 path2/file2 path3/file3 path3/subp3/file3
105do
106 echo "hello $p" >$p
107 ln -s "hello $p" ${p}sym
108done
109test_expect_success \
5be60078
JH
110 'adding various types of objects with git update-index --add.' \
111 'find path* ! -type d -print | xargs git update-index --add'
e1970ce4
JH
112
113# Show them and see that matches what we expect.
114test_expect_success \
5be60078
JH
115 'showing stage with git ls-files --stage' \
116 'git ls-files --stage >current'
e1970ce4
JH
117
118cat >expected <<\EOF
2eab945e
JH
119100644 f87290f8eb2cbbea7857214459a0739927eab154 0 path0
120120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0 path0sym
121100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0 path2/file2
122120000 d8ce161addc5173867a3c3c730924388daedbc38 0 path2/file2sym
123100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0 path3/file3
124120000 8599103969b43aff7e430efea79ca4636466794f 0 path3/file3sym
125100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0 path3/subp3/file3
126120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0 path3/subp3/file3sym
e1970ce4
JH
127EOF
128test_expect_success \
5be60078 129 'validate git ls-files output for a known tree.' \
e1970ce4
JH
130 'diff current expected'
131
132test_expect_success \
5be60078
JH
133 'writing tree out with git write-tree.' \
134 'tree=$(git write-tree)'
e1970ce4
JH
135test_expect_success \
136 'validate object ID for a known tree.' \
137 'test "$tree" = 087704a96baf1c2d1c869a8b084481e121c88b5b'
138
139test_expect_success \
5be60078
JH
140 'showing tree with git ls-tree' \
141 'git ls-tree $tree >current'
e1970ce4 142cat >expected <<\EOF
2eab945e
JH
143100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
144120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
145040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2
146040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
e1970ce4
JH
147EOF
148test_expect_success \
5be60078 149 'git ls-tree output for a known tree.' \
e1970ce4
JH
150 'diff current expected'
151
246cc52f
JH
152# This changed in ls-tree pathspec change -- recursive does
153# not show tree nodes anymore.
e1970ce4 154test_expect_success \
5be60078
JH
155 'showing tree with git ls-tree -r' \
156 'git ls-tree -r $tree >current'
e1970ce4 157cat >expected <<\EOF
2eab945e
JH
158100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
159120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
2eab945e
JH
160100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2
161120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym
2eab945e
JH
162100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3
163120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym
2eab945e
JH
164100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3
165120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym
e1970ce4
JH
166EOF
167test_expect_success \
5be60078 168 'git ls-tree -r output for a known tree.' \
e1970ce4
JH
169 'diff current expected'
170
fdeb6bf5
JH
171# But with -r -t we can have both.
172test_expect_success \
5be60078
JH
173 'showing tree with git ls-tree -r -t' \
174 'git ls-tree -r -t $tree >current'
fdeb6bf5
JH
175cat >expected <<\EOF
176100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
177120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
178040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2
179100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2
180120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym
181040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
182100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3
183120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym
184040000 tree 3c5e5399f3a333eddecce7a9b9465b63f65f51e2 path3/subp3
185100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3
186120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym
187EOF
188test_expect_success \
5be60078 189 'git ls-tree -r output for a known tree.' \
fdeb6bf5
JH
190 'diff current expected'
191
6bd20358 192test_expect_success \
5be60078
JH
193 'writing partial tree out with git write-tree --prefix.' \
194 'ptree=$(git write-tree --prefix=path3)'
6bd20358
JH
195test_expect_success \
196 'validate object ID for a known tree.' \
197 'test "$ptree" = 21ae8269cacbe57ae09138dcc3a2887f904d02b3'
198
199test_expect_success \
5be60078
JH
200 'writing partial tree out with git write-tree --prefix.' \
201 'ptree=$(git write-tree --prefix=path3/subp3)'
6bd20358
JH
202test_expect_success \
203 'validate object ID for a known tree.' \
204 'test "$ptree" = 3c5e5399f3a333eddecce7a9b9465b63f65f51e2'
205
3d12d0cf
JS
206cat >badobjects <<EOF
207100644 blob 1000000000000000000000000000000000000000 dir/file1
208100644 blob 2000000000000000000000000000000000000000 dir/file2
209100644 blob 3000000000000000000000000000000000000000 dir/file3
210100644 blob 4000000000000000000000000000000000000000 dir/file4
211100644 blob 5000000000000000000000000000000000000000 dir/file5
212EOF
213
214rm .git/index
215test_expect_success \
216 'put invalid objects into the index.' \
5be60078 217 'git update-index --index-info < badobjects'
3d12d0cf 218
41ac414e 219test_expect_success 'writing this tree without --missing-ok.' '
d492b31c 220 test_must_fail git write-tree
41ac414e 221'
3d12d0cf
JS
222
223test_expect_success \
224 'writing this tree with --missing-ok.' \
5be60078 225 'git write-tree --missing-ok'
3d12d0cf
JS
226
227
e1970ce4
JH
228################################################################
229rm .git/index
230test_expect_success \
5be60078
JH
231 'git read-tree followed by write-tree should be idempotent.' \
232 'git read-tree $tree &&
e1970ce4 233 test -f .git/index &&
5be60078 234 newtree=$(git write-tree) &&
e1970ce4
JH
235 test "$newtree" = "$tree"'
236
237cat >expected <<\EOF
b6d8f309
JH
238:100644 100644 f87290f8eb2cbbea7857214459a0739927eab154 0000000000000000000000000000000000000000 M path0
239:120000 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0000000000000000000000000000000000000000 M path0sym
240:100644 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0000000000000000000000000000000000000000 M path2/file2
241:120000 120000 d8ce161addc5173867a3c3c730924388daedbc38 0000000000000000000000000000000000000000 M path2/file2sym
242:100644 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0000000000000000000000000000000000000000 M path3/file3
243:120000 120000 8599103969b43aff7e430efea79ca4636466794f 0000000000000000000000000000000000000000 M path3/file3sym
244:100644 100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0000000000000000000000000000000000000000 M path3/subp3/file3
245:120000 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0000000000000000000000000000000000000000 M path3/subp3/file3sym
e1970ce4
JH
246EOF
247test_expect_success \
5be60078
JH
248 'validate git diff-files output for a know cache/work tree state.' \
249 'git diff-files >current && diff >/dev/null -b current expected'
e1970ce4
JH
250
251test_expect_success \
5be60078
JH
252 'git update-index --refresh should succeed.' \
253 'git update-index --refresh'
e1970ce4
JH
254
255test_expect_success \
5be60078
JH
256 'no diff after checkout and git update-index --refresh.' \
257 'git diff-files >current && cmp -s current /dev/null'
e1970ce4 258
9af0b8db
JH
259################################################################
260P=087704a96baf1c2d1c869a8b084481e121c88b5b
261test_expect_success \
5be60078
JH
262 'git commit-tree records the correct tree in a commit.' \
263 'commit0=$(echo NO | git commit-tree $P) &&
9af0b8db
JH
264 tree=$(git show --pretty=raw $commit0 |
265 sed -n -e "s/^tree //p" -e "/^author /q") &&
266 test "z$tree" = "z$P"'
267
268test_expect_success \
5be60078
JH
269 'git commit-tree records the correct parent in a commit.' \
270 'commit1=$(echo NO | git commit-tree $P -p $commit0) &&
9af0b8db
JH
271 parent=$(git show --pretty=raw $commit1 |
272 sed -n -e "s/^parent //p" -e "/^author /q") &&
273 test "z$commit0" = "z$parent"'
274
275test_expect_success \
5be60078
JH
276 'git commit-tree omits duplicated parent in a commit.' \
277 'commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) &&
9af0b8db
JH
278 parent=$(git show --pretty=raw $commit2 |
279 sed -n -e "s/^parent //p" -e "/^author /q" |
280 sort -u) &&
281 test "z$commit0" = "z$parent" &&
282 numparent=$(git show --pretty=raw $commit2 |
283 sed -n -e "s/^parent //p" -e "/^author /q" |
284 wc -l) &&
285 test $numparent = 1'
286
81a361be
JH
287test_expect_success 'update-index D/F conflict' '
288 mv path0 tmp &&
289 mv path2 path0 &&
290 mv tmp path2 &&
291 git update-index --add --replace path2 path0/file2 &&
292 numpath0=$(git ls-files path0 | wc -l) &&
293 test $numpath0 = 1
294'
295
e5392c51
JS
296test_expect_success 'absolute path works as expected' '
297 mkdir first &&
298 ln -s ../.git first/.git &&
299 mkdir second &&
300 ln -s ../first second/other &&
301 mkdir third &&
302 dir="$(cd .git; pwd -P)" &&
303 dir2=third/../second/other/.git &&
d553e737 304 test "$dir" = "$(test-path-utils make_absolute_path $dir2)" &&
e5392c51 305 file="$dir"/index &&
d553e737 306 test "$file" = "$(test-path-utils make_absolute_path $dir2/index)" &&
e371a4c6 307 basename=blub &&
d553e737 308 test "$dir/$basename" = "$(cd .git && test-path-utils make_absolute_path "$basename")" &&
e5392c51
JS
309 ln -s ../first/file .git/syml &&
310 sym="$(cd first; pwd -P)"/file &&
d553e737 311 test "$sym" = "$(test-path-utils make_absolute_path "$dir2/syml")"
e5392c51
JS
312'
313
7fec10b7
JH
314test_expect_success 'very long name in the index handled sanely' '
315
316 a=a && # 1
317 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 16
318 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 256
319 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 4096
320 a=${a}q &&
321
322 >path4 &&
323 git update-index --add path4 &&
324 (
325 git ls-files -s path4 |
326 sed -e "s/ .*/ /" |
327 tr -d "\012"
328 echo "$a"
329 ) | git update-index --index-info &&
330 len=$(git ls-files "a*" | wc -c) &&
331 test $len = 4098
332'
333
e1970ce4 334test_done