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 test "$no_symlinks" && {
38 case "$1" in -*) opt
=$1; shift;; esac
39 tr -d "\015" < $1 > $1.doof
40 grep -v "^:\?120000" < $2 | \
41 sed -e s
/58a09c23e2ca152193f2786e06986b7b6712bdbe
/600f42758e4458c37c2c1f8063378f540b4efad
7/ \
42 -e s
/21ae8269cacbe57ae09138dcc3a2887f904d02b
3/cfb8591b2f65de8b8cc1020cd7d9e67e7793b325
/ \
43 -e s
/3c5e5399f3a333eddecce7a9b9465b63f65f51e
2/ce580448f0148b985a513b693fdf7d802cacb44f
/ \
45 $DIFF $opt $1.doof
$2.doof
49 ################################################################
50 # git init has been done in an empty repository.
51 # make sure it is empty.
53 find .git
/objects
-type f
-print >should-be-empty
55 '.git/objects should be empty after git init in an empty repo.' \
56 'cmp -s /dev/null should-be-empty'
58 # also it should have 2 subdirectories; no fan-out anymore, pack, and info.
59 # 3 is counting "objects" itself
60 find .git
/objects
-type d
-print >full-of-directories
62 '.git/objects should have 3 subdirectories.' \
63 'test $(wc -l < full-of-directories) = 3'
65 ################################################################
66 # Basics of the basics
68 # updating a new file without --add should fail.
70 'git update-index without --add should fail adding.' \
71 'git update-index should-be-empty'
73 # and with --add it should succeed, even if it is empty (it used to fail).
75 'git update-index with --add should succeed.' \
76 'git update-index --add should-be-empty'
79 'writing tree out with git write-tree' \
80 'tree=$(git write-tree)'
82 # we know the shape and contents of the tree and know the object ID for it.
84 'validate object ID of a known tree.' \
85 'test "$tree" = 7bb943559a305bdd6bdee2cef6e5df2413c3d30a'
88 rm -f should-be-empty full-of-directories
90 'git update-index without --remove should fail removing.' \
91 'git update-index should-be-empty'
94 'git update-index with --remove should be able to remove.' \
95 'git update-index --remove should-be-empty'
97 # Empty tree can be written with recent write-tree.
99 'git write-tree should be able to write an empty tree.' \
100 'tree=$(git write-tree)'
102 test_expect_success \
103 'validate object ID of a known tree.' \
104 'test "$tree" = 4b825dc642cb6eb9a060e54bf8d69288fbee4904'
106 # Various types of objects
107 mkdir path2 path3 path
3/subp3
108 for p
in path0 path
2/file2 path
3/file3 path
3/subp
3/file3
111 ln -s "hello $p" ${p}sym
113 test_expect_success \
114 'adding various types of objects with git update-index --add.' \
115 'find path* ! -type d -print | xargs git update-index --add'
117 # Show them and see that matches what we expect.
118 test_expect_success \
119 'showing stage with git ls-files --stage' \
120 'git ls-files --stage >current'
123 100644 f87290f8eb2cbbea7857214459a0739927eab154
0 path0
124 120000 15a98433ae33114b085f3eb3bb03b832b3180a01
0 path0sym
125 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7
0 path
2/file2
126 120000 d8ce161addc5173867a3c3c730924388daedbc38
0 path
2/file2sym
127 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376
0 path
3/file3
128 120000 8599103969b43aff7e430efea79ca4636466794f
0 path
3/file3sym
129 100644 00fb5908cb97c2564a9783c0c64087333b3b464f
0 path
3/subp
3/file3
130 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c
0 path
3/subp
3/file3sym
133 test_expect_success \
134 'validate git ls-files output for a known tree.' \
135 'diff current expected'
137 test_expect_success \
138 'writing tree out with git write-tree.' \
139 'tree=$(git write-tree)'
140 expected_tree
=087704a96baf1c2d1c869a8b084481e121c88b5b
141 test "$no_symlinks" && expected_tree
=8e18edf7d7edcf4371a3ac6ae5f07c2641db7c46
142 test_expect_success \
143 'validate object ID for a known tree.' \
144 'test "$tree" = "$expected_tree"'
146 test_expect_success \
147 'showing tree with git ls-tree' \
148 'git ls-tree $tree >current'
150 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
151 120000 blob
15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
152 040000 tree
58a09c23e2ca152193f2786e06986b7b6712bdbe path2
153 040000 tree
21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
155 test_expect_success \
156 'git ls-tree output for a known tree.' \
157 'diff current expected'
159 # This changed in ls-tree pathspec change -- recursive does
160 # not show tree nodes anymore.
161 test_expect_success \
162 'showing tree with git ls-tree -r' \
163 'git ls-tree -r $tree >current'
165 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
166 120000 blob
15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
167 100644 blob
3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path
2/file2
168 120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path
2/file2sym
169 100644 blob
0aa34cae68d0878578ad119c86ca2b5ed5b28376 path
3/file3
170 120000 blob
8599103969b43aff7e430efea79ca4636466794f path
3/file3sym
171 100644 blob
00fb5908cb97c2564a9783c0c64087333b3b464f path
3/subp
3/file3
172 120000 blob
6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path
3/subp
3/file3sym
174 test_expect_success \
175 'git ls-tree -r output for a known tree.' \
176 'diff current expected'
178 # But with -r -t we can have both.
179 test_expect_success \
180 'showing tree with git ls-tree -r -t' \
181 'git ls-tree -r -t $tree >current'
183 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
184 120000 blob
15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
185 040000 tree
58a09c23e2ca152193f2786e06986b7b6712bdbe path2
186 100644 blob
3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path
2/file2
187 120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path
2/file2sym
188 040000 tree
21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
189 100644 blob
0aa34cae68d0878578ad119c86ca2b5ed5b28376 path
3/file3
190 120000 blob
8599103969b43aff7e430efea79ca4636466794f path
3/file3sym
191 040000 tree
3c5e5399f3a333eddecce7a9b9465b63f65f51e2 path
3/subp3
192 100644 blob
00fb5908cb97c2564a9783c0c64087333b3b464f path
3/subp
3/file3
193 120000 blob
6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path
3/subp
3/file3sym
195 test_expect_success \
196 'git ls-tree -r output for a known tree.' \
197 'diff current expected'
199 test_expect_success \
200 'writing partial tree out with git write-tree --prefix.' \
201 'ptree=$(git write-tree --prefix=path3)'
202 expected_tree
=21ae8269cacbe57ae09138dcc3a2887f904d02b3
203 test "$no_symlinks" && expected_tree
=cfb8591b2f65de8b8cc1020cd7d9e67e7793b325
204 test_expect_success \
205 'validate object ID for a known tree.' \
206 'test "$ptree" = "$expected_tree"'
208 test_expect_success \
209 'writing partial tree out with git write-tree --prefix.' \
210 'ptree=$(git write-tree --prefix=path3/subp3)'
211 expect_tree
=3c5e5399f3a333eddecce7a9b9465b63f65f51e2
212 test "$no_symlinks" && expect_tree
=ce580448f0148b985a513b693fdf7d802cacb44f
213 test_expect_success \
214 'validate object ID for a known tree.' \
215 'test "$ptree" = "$expect_tree"'
217 cat >badobjects
<<EOF
218 100644 blob 1000000000000000000000000000000000000000 dir/file1
219 100644 blob 2000000000000000000000000000000000000000 dir/file2
220 100644 blob 3000000000000000000000000000000000000000 dir/file3
221 100644 blob 4000000000000000000000000000000000000000 dir/file4
222 100644 blob 5000000000000000000000000000000000000000 dir/file5
226 test_expect_success \
227 'put invalid objects into the index.' \
228 'git update-index --index-info < badobjects'
230 test_expect_failure \
231 'writing this tree without --missing-ok.' \
234 test_expect_success \
235 'writing this tree with --missing-ok.' \
236 'git write-tree --missing-ok'
239 ################################################################
241 test_expect_success \
242 'git read-tree followed by write-tree should be idempotent.' \
243 'git read-tree $tree &&
244 test -f .git/index &&
245 newtree=$(git write-tree) &&
246 test "$newtree" = "$tree"'
249 :100644 100644 f87290f8eb2cbbea7857214459a0739927eab154
0000000000000000000000000000000000000000 M path0
250 :120000 120000 15a98433ae33114b085f3eb3bb03b832b3180a01
0000000000000000000000000000000000000000 M path0sym
251 :100644 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7
0000000000000000000000000000000000000000 M path
2/file2
252 :120000 120000 d8ce161addc5173867a3c3c730924388daedbc38
0000000000000000000000000000000000000000 M path
2/file2sym
253 :100644 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376
0000000000000000000000000000000000000000 M path
3/file3
254 :120000 120000 8599103969b43aff7e430efea79ca4636466794f
0000000000000000000000000000000000000000 M path
3/file3sym
255 :100644 100644 00fb5908cb97c2564a9783c0c64087333b3b464f
0000000000000000000000000000000000000000 M path
3/subp
3/file3
256 :120000 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c
0000000000000000000000000000000000000000 M path
3/subp
3/file3sym
258 test_expect_success \
259 'validate git diff-files output for a know cache/work tree state.' \
260 'git diff-files >current && diff >/dev/null -b current expected'
262 test_expect_success \
263 'git update-index --refresh should succeed.' \
264 'git update-index --refresh'
266 test_expect_success \
267 'no diff after checkout and git update-index --refresh.' \
268 'git diff-files >current && cmp -s current /dev/null'
270 ################################################################
271 P
=087704a96baf1c2d1c869a8b084481e121c88b5b
272 test "$no_symlinks" && P
=7bb943559a305bdd6bdee2cef6e5df2413c3d30a
273 test_expect_success \
274 'git commit-tree records the correct tree in a commit.' \
275 'commit0=$(echo NO | git commit-tree $P) &&
276 tree=$(git show --pretty=raw $commit0 |
277 sed -n -e "s/^tree //p" -e "/^author /q") &&
278 test "z$tree" = "z$P"'
280 test_expect_success \
281 'git commit-tree records the correct parent in a commit.' \
282 'commit1=$(echo NO | git commit-tree $P -p $commit0) &&
283 parent=$(git show --pretty=raw $commit1 |
284 sed -n -e "s/^parent //p" -e "/^author /q") &&
285 test "z$commit0" = "z$parent"'
287 test_expect_success \
288 'git commit-tree omits duplicated parent in a commit.' \
289 'commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) &&
290 parent=$(git show --pretty=raw $commit2 |
291 sed -n -e "s/^parent //p" -e "/^author /q" |
293 test "z$commit0" = "z$parent" &&
294 numparent=$(git show --pretty=raw $commit2 |
295 sed -n -e "s/^parent //p" -e "/^author /q" |
299 test_expect_success
'update-index D/F conflict' '
303 git update-index --add --replace path2 path0/file2 &&
304 numpath0=$(git ls-files path0 | wc -l) &&
308 test "$no_symlinks" ||
309 test_expect_success
'absolute path works as expected' '
311 ln -s ../.git first/.git &&
313 ln -s ../first second/other &&
315 dir="$(cd .git; pwd -P)" &&
316 dir2=third/../second/other/.git &&
317 test "$dir" = "$(test-absolute-path $dir2)" &&
319 test "$file" = "$(test-absolute-path $dir2/index)" &&
320 ln -s ../first/file .git/syml &&
321 sym="$(cd first; pwd -P)"/file &&
322 test "$sym" = "$(test-absolute-path $dir2/syml)"