Documentation/SubmittingPatches: What's Acked-by and Tested-by?
[git/dscho.git] / t / t0000-basic.sh
blobcd0de506d208f3d741aa2223e8cc639850326ae7
1 #!/bin/sh
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,
13 writing tree, etc.
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...
24 ../git >/dev/null
25 if test $? != 1
26 then
27 echo >&2 'You do not seem to have built git yet.'
28 exit 1
31 . ./test-lib.sh
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
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'
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'
49 ################################################################
50 # Test harness
51 test_expect_success 'success is reported like this' '
54 test_expect_failure 'pretend we have a known breakage' '
55 false
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 ! git update-index should-be-empty
69 # and with --add it should succeed, even if it is empty (it used to fail).
70 test_expect_success \
71 'git update-index with --add should succeed.' \
72 'git update-index --add should-be-empty'
74 test_expect_success \
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.
79 test_expect_success \
80 'validate object ID of a known tree.' \
81 'test "$tree" = 7bb943559a305bdd6bdee2cef6e5df2413c3d30a'
83 # Removing paths.
84 rm -f should-be-empty full-of-directories
85 test_expect_success 'git update-index without --remove should fail removing.' '
86 ! git update-index should-be-empty
89 test_expect_success \
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.
94 test_expect_success \
95 'git write-tree should be able to write an empty tree.' \
96 'tree=$(git write-tree)'
98 test_expect_success \
99 'validate object ID of a known tree.' \
100 'test "$tree" = 4b825dc642cb6eb9a060e54bf8d69288fbee4904'
102 # Various types of objects
103 mkdir path2 path3 path3/subp3
104 for p in path0 path2/file2 path3/file3 path3/subp3/file3
106 echo "hello $p" >$p
107 ln -s "hello $p" ${p}sym
108 done
109 test_expect_success \
110 'adding various types of objects with git update-index --add.' \
111 'find path* ! -type d -print | xargs git update-index --add'
113 # Show them and see that matches what we expect.
114 test_expect_success \
115 'showing stage with git ls-files --stage' \
116 'git ls-files --stage >current'
118 cat >expected <<\EOF
119 100644 f87290f8eb2cbbea7857214459a0739927eab154 0 path0
120 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0 path0sym
121 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0 path2/file2
122 120000 d8ce161addc5173867a3c3c730924388daedbc38 0 path2/file2sym
123 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0 path3/file3
124 120000 8599103969b43aff7e430efea79ca4636466794f 0 path3/file3sym
125 100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0 path3/subp3/file3
126 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0 path3/subp3/file3sym
128 test_expect_success \
129 'validate git ls-files output for a known tree.' \
130 'diff current expected'
132 test_expect_success \
133 'writing tree out with git write-tree.' \
134 'tree=$(git write-tree)'
135 test_expect_success \
136 'validate object ID for a known tree.' \
137 'test "$tree" = 087704a96baf1c2d1c869a8b084481e121c88b5b'
139 test_expect_success \
140 'showing tree with git ls-tree' \
141 'git ls-tree $tree >current'
142 cat >expected <<\EOF
143 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
144 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
145 040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2
146 040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
148 test_expect_success \
149 'git ls-tree output for a known tree.' \
150 'diff current expected'
152 # This changed in ls-tree pathspec change -- recursive does
153 # not show tree nodes anymore.
154 test_expect_success \
155 'showing tree with git ls-tree -r' \
156 'git ls-tree -r $tree >current'
157 cat >expected <<\EOF
158 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
159 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
160 100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2
161 120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym
162 100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3
163 120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym
164 100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3
165 120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym
167 test_expect_success \
168 'git ls-tree -r output for a known tree.' \
169 'diff current expected'
171 # But with -r -t we can have both.
172 test_expect_success \
173 'showing tree with git ls-tree -r -t' \
174 'git ls-tree -r -t $tree >current'
175 cat >expected <<\EOF
176 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
177 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
178 040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2
179 100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2
180 120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym
181 040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
182 100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3
183 120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym
184 040000 tree 3c5e5399f3a333eddecce7a9b9465b63f65f51e2 path3/subp3
185 100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3
186 120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym
188 test_expect_success \
189 'git ls-tree -r output for a known tree.' \
190 'diff current expected'
192 test_expect_success \
193 'writing partial tree out with git write-tree --prefix.' \
194 'ptree=$(git write-tree --prefix=path3)'
195 test_expect_success \
196 'validate object ID for a known tree.' \
197 'test "$ptree" = 21ae8269cacbe57ae09138dcc3a2887f904d02b3'
199 test_expect_success \
200 'writing partial tree out with git write-tree --prefix.' \
201 'ptree=$(git write-tree --prefix=path3/subp3)'
202 test_expect_success \
203 'validate object ID for a known tree.' \
204 'test "$ptree" = 3c5e5399f3a333eddecce7a9b9465b63f65f51e2'
206 cat >badobjects <<EOF
207 100644 blob 1000000000000000000000000000000000000000 dir/file1
208 100644 blob 2000000000000000000000000000000000000000 dir/file2
209 100644 blob 3000000000000000000000000000000000000000 dir/file3
210 100644 blob 4000000000000000000000000000000000000000 dir/file4
211 100644 blob 5000000000000000000000000000000000000000 dir/file5
214 rm .git/index
215 test_expect_success \
216 'put invalid objects into the index.' \
217 'git update-index --index-info < badobjects'
219 test_expect_success 'writing this tree without --missing-ok.' '
220 ! git write-tree
223 test_expect_success \
224 'writing this tree with --missing-ok.' \
225 'git write-tree --missing-ok'
228 ################################################################
229 rm .git/index
230 test_expect_success \
231 'git read-tree followed by write-tree should be idempotent.' \
232 'git read-tree $tree &&
233 test -f .git/index &&
234 newtree=$(git write-tree) &&
235 test "$newtree" = "$tree"'
237 cat >expected <<\EOF
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
247 test_expect_success \
248 'validate git diff-files output for a know cache/work tree state.' \
249 'git diff-files >current && diff >/dev/null -b current expected'
251 test_expect_success \
252 'git update-index --refresh should succeed.' \
253 'git update-index --refresh'
255 test_expect_success \
256 'no diff after checkout and git update-index --refresh.' \
257 'git diff-files >current && cmp -s current /dev/null'
259 ################################################################
260 P=087704a96baf1c2d1c869a8b084481e121c88b5b
261 test_expect_success \
262 'git commit-tree records the correct tree in a commit.' \
263 'commit0=$(echo NO | git commit-tree $P) &&
264 tree=$(git show --pretty=raw $commit0 |
265 sed -n -e "s/^tree //p" -e "/^author /q") &&
266 test "z$tree" = "z$P"'
268 test_expect_success \
269 'git commit-tree records the correct parent in a commit.' \
270 'commit1=$(echo NO | git commit-tree $P -p $commit0) &&
271 parent=$(git show --pretty=raw $commit1 |
272 sed -n -e "s/^parent //p" -e "/^author /q") &&
273 test "z$commit0" = "z$parent"'
275 test_expect_success \
276 'git commit-tree omits duplicated parent in a commit.' \
277 'commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) &&
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'
287 test_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
296 test_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 &&
304 test "$dir" = "$(test-absolute-path $dir2)" &&
305 file="$dir"/index &&
306 test "$file" = "$(test-absolute-path $dir2/index)" &&
307 ln -s ../first/file .git/syml &&
308 sym="$(cd first; pwd -P)"/file &&
309 test "$sym" = "$(test-absolute-path $dir2/syml)"
312 test_done