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 ################################################################
50 # Basics of the basics
52 # updating a new file without --add should fail.
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).
59 'git-update-index with --add should succeed.' \
60 'git-update-index --add should-be-empty'
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.
68 'validate object ID of a known tree.' \
69 'test "$tree" = 7bb943559a305bdd6bdee2cef6e5df2413c3d30a'
72 rm -f should-be-empty full-of-directories
74 'git-update-index without --remove should fail removing.' \
75 'git-update-index should-be-empty'
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.
83 'git-write-tree should be able to write an empty tree.' \
84 'tree=$(git-write-tree)'
87 'validate object ID of a known tree.' \
88 'test "$tree" = 4b825dc642cb6eb9a060e54bf8d69288fbee4904'
90 # Various types of objects
91 mkdir path2 path3 path
3/subp3
92 for p
in path0 path
2/file2 path
3/file3 path
3/subp
3/file3
95 ln -s "hello $p" ${p}sym
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'
107 100644 f87290f8eb2cbbea7857214459a0739927eab154
0 path0
108 120000 15a98433ae33114b085f3eb3bb03b832b3180a01
0 path0sym
109 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7
0 path
2/file2
110 120000 d8ce161addc5173867a3c3c730924388daedbc38
0 path
2/file2sym
111 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376
0 path
3/file3
112 120000 8599103969b43aff7e430efea79ca4636466794f
0 path
3/file3sym
113 100644 00fb5908cb97c2564a9783c0c64087333b3b464f
0 path
3/subp
3/file3
114 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c
0 path
3/subp
3/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'
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'
146 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
147 120000 blob
15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
148 100644 blob
3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path
2/file2
149 120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path
2/file2sym
150 100644 blob
0aa34cae68d0878578ad119c86ca2b5ed5b28376 path
3/file3
151 120000 blob
8599103969b43aff7e430efea79ca4636466794f path
3/file3sym
152 100644 blob
00fb5908cb97c2564a9783c0c64087333b3b464f path
3/subp
3/file3
153 120000 blob
6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path
3/subp
3/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'
164 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
165 120000 blob
15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
166 040000 tree
58a09c23e2ca152193f2786e06986b7b6712bdbe path2
167 100644 blob
3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path
2/file2
168 120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path
2/file2sym
169 040000 tree
21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
170 100644 blob
0aa34cae68d0878578ad119c86ca2b5ed5b28376 path
3/file3
171 120000 blob
8599103969b43aff7e430efea79ca4636466794f path
3/file3sym
172 040000 tree
3c5e5399f3a333eddecce7a9b9465b63f65f51e2 path
3/subp3
173 100644 blob
00fb5908cb97c2564a9783c0c64087333b3b464f path
3/subp
3/file3
174 120000 blob
6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path
3/subp
3/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
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.' \
211 test_expect_success \
212 'writing this tree with --missing-ok.' \
213 'git-write-tree --missing-ok'
216 ################################################################
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"'
226 :100644 100644 f87290f8eb2cbbea7857214459a0739927eab154
0000000000000000000000000000000000000000 M path0
227 :120000 120000 15a98433ae33114b085f3eb3bb03b832b3180a01
0000000000000000000000000000000000000000 M path0sym
228 :100644 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7
0000000000000000000000000000000000000000 M path
2/file2
229 :120000 120000 d8ce161addc5173867a3c3c730924388daedbc38
0000000000000000000000000000000000000000 M path
2/file2sym
230 :100644 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376
0000000000000000000000000000000000000000 M path
3/file3
231 :120000 120000 8599103969b43aff7e430efea79ca4636466794f
0000000000000000000000000000000000000000 M path
3/file3sym
232 :100644 100644 00fb5908cb97c2564a9783c0c64087333b3b464f
0000000000000000000000000000000000000000 M path
3/subp
3/file3
233 :120000 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c
0000000000000000000000000000000000000000 M path
3/subp
3/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" |
269 test "z$commit0" = "z$parent" &&
270 numparent=$(git show --pretty=raw $commit2 |
271 sed -n -e "s/^parent //p" -e "/^author /q" |
275 test_expect_success
'update-index D/F conflict' '
279 git update-index --add --replace path2 path0/file2 &&
280 numpath0=$(git ls-files path0 | wc -l) &&