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# Basics of the basics 51 52# updating a new file without --add should fail. 53test_expect_failure \ 54'git-update-index without --add should fail adding.' \ 55'git-update-index should-be-empty' 56 57# and with --add it should succeed, even if it is empty (it used to fail). 58test_expect_success \ 59'git-update-index with --add should succeed.' \ 60'git-update-index --add should-be-empty' 61 62test_expect_success \ 63'writing tree out with git-write-tree' \ 64'tree=$(git-write-tree)' 65 66# we know the shape and contents of the tree and know the object ID for it. 67test_expect_success \ 68'validate object ID of a known tree.' \ 69'test "$tree" = 7bb943559a305bdd6bdee2cef6e5df2413c3d30a' 70 71# Removing paths. 72rm-f should-be-empty full-of-directories 73test_expect_failure \ 74'git-update-index without --remove should fail removing.' \ 75'git-update-index should-be-empty' 76 77test_expect_success \ 78'git-update-index with --remove should be able to remove.' \ 79'git-update-index --remove should-be-empty' 80 81# Empty tree can be written with recent write-tree. 82test_expect_success \ 83'git-write-tree should be able to write an empty tree.' \ 84'tree=$(git-write-tree)' 85 86test_expect_success \ 87'validate object ID of a known tree.' \ 88'test "$tree" = 4b825dc642cb6eb9a060e54bf8d69288fbee4904' 89 90# Various types of objects 91mkdir path2 path3 path3/subp3 92for p in path0 path2/file2 path3/file3 path3/subp3/file3 93do 94echo"hello$p">$p 95ln-s"hello$p"${p}sym 96done 97test_expect_success \ 98'adding various types of objects with git-update-index --add.' \ 99'find path* ! -type d -print | xargs git-update-index --add' 100 101# Show them and see that matches what we expect. 102test_expect_success \ 103'showing stage with git-ls-files --stage' \ 104'git-ls-files --stage >current' 105 106cat>expected <<\EOF 107100644 f87290f8eb2cbbea7857214459a0739927eab154 0 path0 108120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0 path0sym 109100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0 path2/file2 110120000 d8ce161addc5173867a3c3c730924388daedbc38 0 path2/file2sym 111100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0 path3/file3 112120000 8599103969b43aff7e430efea79ca4636466794f 0 path3/file3sym 113100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0 path3/subp3/file3 114120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0 path3/subp3/file3sym 115EOF 116test_expect_success \ 117'validate git-ls-files output for a known tree.' \ 118'diff current expected' 119 120test_expect_success \ 121'writing tree out with git-write-tree.' \ 122'tree=$(git-write-tree)' 123test_expect_success \ 124'validate object ID for a known tree.' \ 125'test "$tree" = 087704a96baf1c2d1c869a8b084481e121c88b5b' 126 127test_expect_success \ 128'showing tree with git-ls-tree' \ 129'git-ls-tree$tree>current' 130cat>expected <<\EOF 131100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0 132120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym 133040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2 134040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3 135EOF 136test_expect_success \ 137'git-ls-tree output for a known tree.' \ 138'diff current expected' 139 140# This changed in ls-tree pathspec change -- recursive does 141# not show tree nodes anymore. 142test_expect_success \ 143'showing tree with git-ls-tree -r' \ 144'git-ls-tree -r$tree>current' 145cat>expected <<\EOF 146100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0 147120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym 148100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2 149120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym 150100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3 151120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym 152100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3 153120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym 154EOF 155test_expect_success \ 156'git-ls-tree -r output for a known tree.' \ 157'diff current expected' 158 159# But with -r -t we can have both. 160test_expect_success \ 161'showing tree with git-ls-tree -r -t' \ 162'git-ls-tree -r -t$tree>current' 163cat>expected <<\EOF 164100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0 165120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym 166040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2 167100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2 168120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym 169040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3 170100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3 171120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym 172040000 tree 3c5e5399f3a333eddecce7a9b9465b63f65f51e2 path3/subp3 173100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3 174120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym 175EOF 176test_expect_success \ 177'git-ls-tree -r output for a known tree.' \ 178'diff current expected' 179 180test_expect_success \ 181'writing partial tree out with git-write-tree --prefix.' \ 182'ptree=$(git-write-tree --prefix=path3)' 183test_expect_success \ 184'validate object ID for a known tree.' \ 185'test "$ptree" = 21ae8269cacbe57ae09138dcc3a2887f904d02b3' 186 187test_expect_success \ 188'writing partial tree out with git-write-tree --prefix.' \ 189'ptree=$(git-write-tree --prefix=path3/subp3)' 190test_expect_success \ 191'validate object ID for a known tree.' \ 192'test "$ptree" = 3c5e5399f3a333eddecce7a9b9465b63f65f51e2' 193 194cat>badobjects <<EOF 195100644 blob 1000000000000000000000000000000000000000 dir/file1 196100644 blob 2000000000000000000000000000000000000000 dir/file2 197100644 blob 3000000000000000000000000000000000000000 dir/file3 198100644 blob 4000000000000000000000000000000000000000 dir/file4 199100644 blob 5000000000000000000000000000000000000000 dir/file5 200EOF 201 202rm .git/index 203test_expect_success \ 204'put invalid objects into the index.' \ 205'git-update-index --index-info < badobjects' 206 207test_expect_failure \ 208'writing this tree without --missing-ok.' \ 209'git-write-tree' 210 211test_expect_success \ 212'writing this tree with --missing-ok.' \ 213'git-write-tree --missing-ok' 214 215 216################################################################ 217rm .git/index 218test_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"' 224 225cat>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 234EOF 235test_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' 238 239test_expect_success \ 240'git-update-index --refresh should succeed.' \ 241'git-update-index --refresh' 242 243test_expect_success \ 244'no diff after checkout and git-update-index --refresh.' \ 245'git-diff-files >current && cmp -s current /dev/null' 246 247################################################################ 248P=087704a96baf1c2d1c869a8b084481e121c88b5b 249test_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"' 255 256test_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"' 262 263test_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' 274 275test_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 282' 283 284test_done