Rewrite "git-frotz" to "git frotz"
[git/git-svn.git] / t / t0000-basic.sh
blob4bba9c0717731bfc6912ac28f98c10aa0f3e17fd
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 # Basics of the basics
52 # updating a new file without --add should fail.
53 test_expect_failure \
54 'git update-index without --add should fail adding.' \
55 'git update-index should-be-empty'
57 # and with --add it should succeed, even if it is empty (it used to fail).
58 test_expect_success \
59 'git update-index with --add should succeed.' \
60 'git update-index --add should-be-empty'
62 test_expect_success \
63 'writing tree out with git write-tree' \
64 'tree=$(git write-tree)'
66 # we know the shape and contents of the tree and know the object ID for it.
67 test_expect_success \
68 'validate object ID of a known tree.' \
69 'test "$tree" = 7bb943559a305bdd6bdee2cef6e5df2413c3d30a'
71 # Removing paths.
72 rm -f should-be-empty full-of-directories
73 test_expect_failure \
74 'git update-index without --remove should fail removing.' \
75 'git update-index should-be-empty'
77 test_expect_success \
78 'git update-index with --remove should be able to remove.' \
79 'git update-index --remove should-be-empty'
81 # Empty tree can be written with recent write-tree.
82 test_expect_success \
83 'git write-tree should be able to write an empty tree.' \
84 'tree=$(git write-tree)'
86 test_expect_success \
87 'validate object ID of a known tree.' \
88 'test "$tree" = 4b825dc642cb6eb9a060e54bf8d69288fbee4904'
90 # Various types of objects
91 mkdir path2 path3 path3/subp3
92 for p in path0 path2/file2 path3/file3 path3/subp3/file3
94 echo "hello $p" >$p
95 ln -s "hello $p" ${p}sym
96 done
97 test_expect_success \
98 'adding various types of objects with git update-index --add.' \
99 'find path* ! -type d -print | xargs git update-index --add'
101 # Show them and see that matches what we expect.
102 test_expect_success \
103 'showing stage with git ls-files --stage' \
104 'git ls-files --stage >current'
106 cat >expected <<\EOF
107 100644 f87290f8eb2cbbea7857214459a0739927eab154 0 path0
108 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0 path0sym
109 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0 path2/file2
110 120000 d8ce161addc5173867a3c3c730924388daedbc38 0 path2/file2sym
111 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0 path3/file3
112 120000 8599103969b43aff7e430efea79ca4636466794f 0 path3/file3sym
113 100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0 path3/subp3/file3
114 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0 path3/subp3/file3sym
116 test_expect_success \
117 'validate git ls-files output for a known tree.' \
118 'diff current expected'
120 test_expect_success \
121 'writing tree out with git write-tree.' \
122 'tree=$(git write-tree)'
123 test_expect_success \
124 'validate object ID for a known tree.' \
125 'test "$tree" = 087704a96baf1c2d1c869a8b084481e121c88b5b'
127 test_expect_success \
128 'showing tree with git ls-tree' \
129 'git ls-tree $tree >current'
130 cat >expected <<\EOF
131 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
132 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
133 040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2
134 040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
136 test_expect_success \
137 'git ls-tree output for a known tree.' \
138 'diff current expected'
140 # This changed in ls-tree pathspec change -- recursive does
141 # not show tree nodes anymore.
142 test_expect_success \
143 'showing tree with git ls-tree -r' \
144 'git ls-tree -r $tree >current'
145 cat >expected <<\EOF
146 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
147 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
148 100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2
149 120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym
150 100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3
151 120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym
152 100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3
153 120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym
155 test_expect_success \
156 'git ls-tree -r output for a known tree.' \
157 'diff current expected'
159 # But with -r -t we can have both.
160 test_expect_success \
161 'showing tree with git ls-tree -r -t' \
162 'git ls-tree -r -t $tree >current'
163 cat >expected <<\EOF
164 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
165 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
166 040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2
167 100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2
168 120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym
169 040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
170 100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3
171 120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym
172 040000 tree 3c5e5399f3a333eddecce7a9b9465b63f65f51e2 path3/subp3
173 100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3
174 120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym
176 test_expect_success \
177 'git ls-tree -r output for a known tree.' \
178 'diff current expected'
180 test_expect_success \
181 'writing partial tree out with git write-tree --prefix.' \
182 'ptree=$(git write-tree --prefix=path3)'
183 test_expect_success \
184 'validate object ID for a known tree.' \
185 'test "$ptree" = 21ae8269cacbe57ae09138dcc3a2887f904d02b3'
187 test_expect_success \
188 'writing partial tree out with git write-tree --prefix.' \
189 'ptree=$(git write-tree --prefix=path3/subp3)'
190 test_expect_success \
191 'validate object ID for a known tree.' \
192 'test "$ptree" = 3c5e5399f3a333eddecce7a9b9465b63f65f51e2'
194 cat >badobjects <<EOF
195 100644 blob 1000000000000000000000000000000000000000 dir/file1
196 100644 blob 2000000000000000000000000000000000000000 dir/file2
197 100644 blob 3000000000000000000000000000000000000000 dir/file3
198 100644 blob 4000000000000000000000000000000000000000 dir/file4
199 100644 blob 5000000000000000000000000000000000000000 dir/file5
202 rm .git/index
203 test_expect_success \
204 'put invalid objects into the index.' \
205 'git update-index --index-info < badobjects'
207 test_expect_failure \
208 'writing this tree without --missing-ok.' \
209 'git write-tree'
211 test_expect_success \
212 'writing this tree with --missing-ok.' \
213 'git write-tree --missing-ok'
216 ################################################################
217 rm .git/index
218 test_expect_success \
219 'git read-tree followed by write-tree should be idempotent.' \
220 'git read-tree $tree &&
221 test -f .git/index &&
222 newtree=$(git write-tree) &&
223 test "$newtree" = "$tree"'
225 cat >expected <<\EOF
226 :100644 100644 f87290f8eb2cbbea7857214459a0739927eab154 0000000000000000000000000000000000000000 M path0
227 :120000 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0000000000000000000000000000000000000000 M path0sym
228 :100644 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0000000000000000000000000000000000000000 M path2/file2
229 :120000 120000 d8ce161addc5173867a3c3c730924388daedbc38 0000000000000000000000000000000000000000 M path2/file2sym
230 :100644 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0000000000000000000000000000000000000000 M path3/file3
231 :120000 120000 8599103969b43aff7e430efea79ca4636466794f 0000000000000000000000000000000000000000 M path3/file3sym
232 :100644 100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0000000000000000000000000000000000000000 M path3/subp3/file3
233 :120000 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0000000000000000000000000000000000000000 M path3/subp3/file3sym
235 test_expect_success \
236 'validate git diff-files output for a know cache/work tree state.' \
237 'git diff-files >current && diff >/dev/null -b current expected'
239 test_expect_success \
240 'git update-index --refresh should succeed.' \
241 'git update-index --refresh'
243 test_expect_success \
244 'no diff after checkout and git update-index --refresh.' \
245 'git diff-files >current && cmp -s current /dev/null'
247 ################################################################
248 P=087704a96baf1c2d1c869a8b084481e121c88b5b
249 test_expect_success \
250 'git commit-tree records the correct tree in a commit.' \
251 'commit0=$(echo NO | git commit-tree $P) &&
252 tree=$(git show --pretty=raw $commit0 |
253 sed -n -e "s/^tree //p" -e "/^author /q") &&
254 test "z$tree" = "z$P"'
256 test_expect_success \
257 'git commit-tree records the correct parent in a commit.' \
258 'commit1=$(echo NO | git commit-tree $P -p $commit0) &&
259 parent=$(git show --pretty=raw $commit1 |
260 sed -n -e "s/^parent //p" -e "/^author /q") &&
261 test "z$commit0" = "z$parent"'
263 test_expect_success \
264 'git commit-tree omits duplicated parent in a commit.' \
265 'commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) &&
266 parent=$(git show --pretty=raw $commit2 |
267 sed -n -e "s/^parent //p" -e "/^author /q" |
268 sort -u) &&
269 test "z$commit0" = "z$parent" &&
270 numparent=$(git show --pretty=raw $commit2 |
271 sed -n -e "s/^parent //p" -e "/^author /q" |
272 wc -l) &&
273 test $numparent = 1'
275 test_expect_success 'update-index D/F conflict' '
276 mv path0 tmp &&
277 mv path2 path0 &&
278 mv tmp path2 &&
279 git update-index --add --replace path2 path0/file2 &&
280 numpath0=$(git ls-files path0 | wc -l) &&
281 test $numpath0 = 1
284 test_done