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' 20 21################################################################ 22# It appears that people try to run tests without building... 23 24../git >/dev/null 25iftest $? !=1 26then 27echo>&2'You do not seem to have built git yet.' 28exit1 29fi 30 31. ./test-lib.sh 32 33################################################################ 34# git init has been done in an empty repository. 35# make sure it is empty. 36 37find .git/objects -type f -print>should-be-empty 38test_expect_success \ 39'.git/objects should be empty after git init in an empty repo.' \ 40'cmp -s /dev/null should-be-empty' 41 42# also it should have 2 subdirectories; no fan-out anymore, pack, and info. 43# 3 is counting "objects" itself 44find .git/objects -type d -print>full-of-directories 45test_expect_success \ 46'.git/objects should have 3 subdirectories.' \ 47'test$(wc -l < full-of-directories)= 3' 48 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 61################################################################ 62# Basics of the basics 63 64# updating a new file without --add should fail. 65test_expect_success 'git update-index without --add should fail adding.'' 66 ! git update-index should-be-empty 67' 68 69# and with --add it should succeed, even if it is empty (it used to fail). 70test_expect_success \ 71'git update-index with --add should succeed.' \ 72'git update-index --add should-be-empty' 73 74test_expect_success \ 75'writing tree out with git write-tree' \ 76'tree=$(git write-tree)' 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 85test_expect_success 'git update-index without --remove should fail removing.'' 86 ! git update-index should-be-empty 87' 88 89test_expect_success \ 90'git update-index with --remove should be able to remove.' \ 91'git update-index --remove should-be-empty' 92 93# Empty tree can be written with recent write-tree. 94test_expect_success \ 95'git write-tree should be able to write an empty tree.' \ 96'tree=$(git write-tree)' 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 106echo"hello$p">$p 107ln-s"hello$p"${p}sym 108done 109test_expect_success \ 110'adding various types of objects with git update-index --add.' \ 111'find path* ! -type d -print | xargs git update-index --add' 112 113# Show them and see that matches what we expect. 114test_expect_success \ 115'showing stage with git ls-files --stage' \ 116'git ls-files --stage >current' 117 118cat>expected <<\EOF 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 127EOF 128test_expect_success \ 129'validate git ls-files output for a known tree.' \ 130'diff current expected' 131 132test_expect_success \ 133'writing tree out with git write-tree.' \ 134'tree=$(git write-tree)' 135test_expect_success \ 136'validate object ID for a known tree.' \ 137'test "$tree" = 087704a96baf1c2d1c869a8b084481e121c88b5b' 138 139test_expect_success \ 140'showing tree with git ls-tree' \ 141'git ls-tree$tree>current' 142cat>expected <<\EOF 143100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0 144120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym 145040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2 146040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3 147EOF 148test_expect_success \ 149'git ls-tree output for a known tree.' \ 150'diff current expected' 151 152# This changed in ls-tree pathspec change -- recursive does 153# not show tree nodes anymore. 154test_expect_success \ 155'showing tree with git ls-tree -r' \ 156'git ls-tree -r$tree>current' 157cat>expected <<\EOF 158100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0 159120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym 160100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2 161120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym 162100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3 163120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym 164100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3 165120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym 166EOF 167test_expect_success \ 168'git ls-tree -r output for a known tree.' \ 169'diff current expected' 170 171# But with -r -t we can have both. 172test_expect_success \ 173'showing tree with git ls-tree -r -t' \ 174'git ls-tree -r -t$tree>current' 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 \ 189'git ls-tree -r output for a known tree.' \ 190'diff current expected' 191 192test_expect_success \ 193'writing partial tree out with git write-tree --prefix.' \ 194'ptree=$(git write-tree --prefix=path3)' 195test_expect_success \ 196'validate object ID for a known tree.' \ 197'test "$ptree" = 21ae8269cacbe57ae09138dcc3a2887f904d02b3' 198 199test_expect_success \ 200'writing partial tree out with git write-tree --prefix.' \ 201'ptree=$(git write-tree --prefix=path3/subp3)' 202test_expect_success \ 203'validate object ID for a known tree.' \ 204'test "$ptree" = 3c5e5399f3a333eddecce7a9b9465b63f65f51e2' 205 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.' \ 217'git update-index --index-info < badobjects' 218 219test_expect_success 'writing this tree without --missing-ok.'' 220 ! git write-tree 221' 222 223test_expect_success \ 224'writing this tree with --missing-ok.' \ 225'git write-tree --missing-ok' 226 227 228################################################################ 229rm .git/index 230test_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"' 236 237cat>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 246EOF 247test_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' 250 251test_expect_success \ 252'git update-index --refresh should succeed.' \ 253'git update-index --refresh' 254 255test_expect_success \ 256'no diff after checkout and git update-index --refresh.' \ 257'git diff-files >current && cmp -s current /dev/null' 258 259################################################################ 260P=087704a96baf1c2d1c869a8b084481e121c88b5b 261test_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"' 267 268test_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"' 274 275test_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' 286 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 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 && 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)" 310' 311 312test_expect_success 'very long name in the index handled sanely'' 313 314 a=a && # 1 315 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a&& # 16 316 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a&& # 256 317 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a&& # 4096 318 a=${a}q && 319 320 >path4 && 321 git update-index --add path4 && 322 ( 323 git ls-files -s path4 | 324 sed -e "s/ .*/ /" | 325 tr -d "\012" 326 echo "$a" 327 ) | git update-index --index-info && 328 len=$(git ls-files "a*" | wc -c)&& 329 test$len= 4098 330' 331 332test_done