t / t0000-basic.shon commit t/t3300-funny-names: change from skip_all=* to prereq skip (e1697cc)
   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
  25if test $? != 1
  26then
  27        echo >&2 'You do not seem to have built git yet.'
  28        exit 1
  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'
  60test_set_prereq HAVEIT
  61haveit=no
  62test_expect_success HAVEIT 'test runs if prerequisite is satisfied' '
  63    test_have_prereq HAVEIT &&
  64    haveit=yes
  65'
  66donthaveit=yes
  67test_expect_success DONTHAVEIT 'unmet prerequisite causes test to be skipped' '
  68    donthaveit=no
  69'
  70if test $haveit$donthaveit != yesyes
  71then
  72        say "bug in test framework: prerequisite tags do not work reliably"
  73        exit 1
  74fi
  75
  76test_set_prereq HAVETHIS
  77haveit=no
  78test_expect_success HAVETHIS,HAVEIT 'test runs if prerequisites are satisfied' '
  79    test_have_prereq HAVEIT &&
  80    test_have_prereq HAVETHIS &&
  81    haveit=yes
  82'
  83donthaveit=yes
  84test_expect_success HAVEIT,DONTHAVEIT 'unmet prerequisites causes test to be skipped' '
  85    donthaveit=no
  86'
  87donthaveiteither=yes
  88test_expect_success DONTHAVEIT,HAVEIT 'unmet prerequisites causes test to be skipped' '
  89    donthaveiteither=no
  90'
  91if test $haveit$donthaveit$donthaveiteither != yesyesyes
  92then
  93        say "bug in test framework: multiple prerequisite tags do not work reliably"
  94        exit 1
  95fi
  96
  97clean=no
  98test_expect_success 'tests clean up after themselves' '
  99    test_when_finished clean=yes
 100'
 101
 102cleaner=no
 103test_expect_code 1 'tests clean up even after a failure' '
 104    test_when_finished cleaner=yes &&
 105    (exit 1)
 106'
 107
 108if test $clean$cleaner != yesyes
 109then
 110        say "bug in test framework: cleanup commands do not work reliably"
 111        exit 1
 112fi
 113
 114test_expect_code 2 'failure to clean up causes the test to fail' '
 115    test_when_finished "(exit 2)"
 116'
 117
 118################################################################
 119# Basics of the basics
 120
 121# updating a new file without --add should fail.
 122test_expect_success 'git update-index without --add should fail adding.' '
 123    test_must_fail git update-index should-be-empty
 124'
 125
 126# and with --add it should succeed, even if it is empty (it used to fail).
 127test_expect_success \
 128    'git update-index with --add should succeed.' \
 129    'git update-index --add should-be-empty'
 130
 131test_expect_success \
 132    'writing tree out with git write-tree' \
 133    'tree=$(git write-tree)'
 134
 135# we know the shape and contents of the tree and know the object ID for it.
 136test_expect_success \
 137    'validate object ID of a known tree.' \
 138    'test "$tree" = 7bb943559a305bdd6bdee2cef6e5df2413c3d30a'
 139
 140# Removing paths.
 141rm -f should-be-empty full-of-directories
 142test_expect_success 'git update-index without --remove should fail removing.' '
 143    test_must_fail git update-index should-be-empty
 144'
 145
 146test_expect_success \
 147    'git update-index with --remove should be able to remove.' \
 148    'git update-index --remove should-be-empty'
 149
 150# Empty tree can be written with recent write-tree.
 151test_expect_success \
 152    'git write-tree should be able to write an empty tree.' \
 153    'tree=$(git write-tree)'
 154
 155test_expect_success \
 156    'validate object ID of a known tree.' \
 157    'test "$tree" = 4b825dc642cb6eb9a060e54bf8d69288fbee4904'
 158
 159# Various types of objects
 160# Some filesystems do not support symblic links; on such systems
 161# some expected values are different
 162mkdir path2 path3 path3/subp3
 163paths='path0 path2/file2 path3/file3 path3/subp3/file3'
 164for p in $paths
 165do
 166    echo "hello $p" >$p
 167done
 168if test_have_prereq SYMLINKS
 169then
 170        for p in $paths
 171        do
 172                ln -s "hello $p" ${p}sym
 173        done
 174        expectfilter=cat
 175        expectedtree=087704a96baf1c2d1c869a8b084481e121c88b5b
 176        expectedptree1=21ae8269cacbe57ae09138dcc3a2887f904d02b3
 177        expectedptree2=3c5e5399f3a333eddecce7a9b9465b63f65f51e2
 178else
 179        expectfilter='grep -v sym'
 180        expectedtree=8e18edf7d7edcf4371a3ac6ae5f07c2641db7c46
 181        expectedptree1=cfb8591b2f65de8b8cc1020cd7d9e67e7793b325
 182        expectedptree2=ce580448f0148b985a513b693fdf7d802cacb44f
 183fi
 184
 185test_expect_success \
 186    'adding various types of objects with git update-index --add.' \
 187    'find path* ! -type d -print | xargs git update-index --add'
 188
 189# Show them and see that matches what we expect.
 190test_expect_success \
 191    'showing stage with git ls-files --stage' \
 192    'git ls-files --stage >current'
 193
 194$expectfilter >expected <<\EOF
 195100644 f87290f8eb2cbbea7857214459a0739927eab154 0       path0
 196120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0       path0sym
 197100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0       path2/file2
 198120000 d8ce161addc5173867a3c3c730924388daedbc38 0       path2/file2sym
 199100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0       path3/file3
 200120000 8599103969b43aff7e430efea79ca4636466794f 0       path3/file3sym
 201100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0       path3/subp3/file3
 202120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0       path3/subp3/file3sym
 203EOF
 204test_expect_success \
 205    'validate git ls-files output for a known tree.' \
 206    'test_cmp expected current'
 207
 208test_expect_success \
 209    'writing tree out with git write-tree.' \
 210    'tree=$(git write-tree)'
 211test_expect_success \
 212    'validate object ID for a known tree.' \
 213    'test "$tree" = "$expectedtree"'
 214
 215test_expect_success \
 216    'showing tree with git ls-tree' \
 217    'git ls-tree $tree >current'
 218cat >expected <<\EOF
 219100644 blob f87290f8eb2cbbea7857214459a0739927eab154    path0
 220120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01    path0sym
 221040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe    path2
 222040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3    path3
 223EOF
 224test_expect_success SYMLINKS \
 225    'git ls-tree output for a known tree.' \
 226    'test_cmp expected current'
 227
 228# This changed in ls-tree pathspec change -- recursive does
 229# not show tree nodes anymore.
 230test_expect_success \
 231    'showing tree with git ls-tree -r' \
 232    'git ls-tree -r $tree >current'
 233$expectfilter >expected <<\EOF
 234100644 blob f87290f8eb2cbbea7857214459a0739927eab154    path0
 235120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01    path0sym
 236100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7    path2/file2
 237120000 blob d8ce161addc5173867a3c3c730924388daedbc38    path2/file2sym
 238100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376    path3/file3
 239120000 blob 8599103969b43aff7e430efea79ca4636466794f    path3/file3sym
 240100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f    path3/subp3/file3
 241120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c    path3/subp3/file3sym
 242EOF
 243test_expect_success \
 244    'git ls-tree -r output for a known tree.' \
 245    'test_cmp expected current'
 246
 247# But with -r -t we can have both.
 248test_expect_success \
 249    'showing tree with git ls-tree -r -t' \
 250    'git ls-tree -r -t $tree >current'
 251cat >expected <<\EOF
 252100644 blob f87290f8eb2cbbea7857214459a0739927eab154    path0
 253120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01    path0sym
 254040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe    path2
 255100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7    path2/file2
 256120000 blob d8ce161addc5173867a3c3c730924388daedbc38    path2/file2sym
 257040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3    path3
 258100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376    path3/file3
 259120000 blob 8599103969b43aff7e430efea79ca4636466794f    path3/file3sym
 260040000 tree 3c5e5399f3a333eddecce7a9b9465b63f65f51e2    path3/subp3
 261100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f    path3/subp3/file3
 262120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c    path3/subp3/file3sym
 263EOF
 264test_expect_success SYMLINKS \
 265    'git ls-tree -r output for a known tree.' \
 266    'test_cmp expected current'
 267
 268test_expect_success \
 269    'writing partial tree out with git write-tree --prefix.' \
 270    'ptree=$(git write-tree --prefix=path3)'
 271test_expect_success \
 272    'validate object ID for a known tree.' \
 273    'test "$ptree" = "$expectedptree1"'
 274
 275test_expect_success \
 276    'writing partial tree out with git write-tree --prefix.' \
 277    'ptree=$(git write-tree --prefix=path3/subp3)'
 278test_expect_success \
 279    'validate object ID for a known tree.' \
 280    'test "$ptree" = "$expectedptree2"'
 281
 282cat >badobjects <<EOF
 283100644 blob 1000000000000000000000000000000000000000    dir/file1
 284100644 blob 2000000000000000000000000000000000000000    dir/file2
 285100644 blob 3000000000000000000000000000000000000000    dir/file3
 286100644 blob 4000000000000000000000000000000000000000    dir/file4
 287100644 blob 5000000000000000000000000000000000000000    dir/file5
 288EOF
 289
 290rm .git/index
 291test_expect_success \
 292    'put invalid objects into the index.' \
 293    'git update-index --index-info < badobjects'
 294
 295test_expect_success 'writing this tree without --missing-ok.' '
 296    test_must_fail git write-tree
 297'
 298
 299test_expect_success \
 300    'writing this tree with --missing-ok.' \
 301    'git write-tree --missing-ok'
 302
 303
 304################################################################
 305rm .git/index
 306test_expect_success \
 307    'git read-tree followed by write-tree should be idempotent.' \
 308    'git read-tree $tree &&
 309     test -f .git/index &&
 310     newtree=$(git write-tree) &&
 311     test "$newtree" = "$tree"'
 312
 313$expectfilter >expected <<\EOF
 314:100644 100644 f87290f8eb2cbbea7857214459a0739927eab154 0000000000000000000000000000000000000000 M      path0
 315:120000 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0000000000000000000000000000000000000000 M      path0sym
 316:100644 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0000000000000000000000000000000000000000 M      path2/file2
 317:120000 120000 d8ce161addc5173867a3c3c730924388daedbc38 0000000000000000000000000000000000000000 M      path2/file2sym
 318:100644 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0000000000000000000000000000000000000000 M      path3/file3
 319:120000 120000 8599103969b43aff7e430efea79ca4636466794f 0000000000000000000000000000000000000000 M      path3/file3sym
 320:100644 100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0000000000000000000000000000000000000000 M      path3/subp3/file3
 321:120000 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0000000000000000000000000000000000000000 M      path3/subp3/file3sym
 322EOF
 323test_expect_success \
 324    'validate git diff-files output for a know cache/work tree state.' \
 325    'git diff-files >current && test_cmp current expected >/dev/null'
 326
 327test_expect_success \
 328    'git update-index --refresh should succeed.' \
 329    'git update-index --refresh'
 330
 331test_expect_success \
 332    'no diff after checkout and git update-index --refresh.' \
 333    'git diff-files >current && cmp -s current /dev/null'
 334
 335################################################################
 336P=$expectedtree
 337test_expect_success \
 338    'git commit-tree records the correct tree in a commit.' \
 339    'commit0=$(echo NO | git commit-tree $P) &&
 340     tree=$(git show --pretty=raw $commit0 |
 341         sed -n -e "s/^tree //p" -e "/^author /q") &&
 342     test "z$tree" = "z$P"'
 343
 344test_expect_success \
 345    'git commit-tree records the correct parent in a commit.' \
 346    'commit1=$(echo NO | git commit-tree $P -p $commit0) &&
 347     parent=$(git show --pretty=raw $commit1 |
 348         sed -n -e "s/^parent //p" -e "/^author /q") &&
 349     test "z$commit0" = "z$parent"'
 350
 351test_expect_success \
 352    'git commit-tree omits duplicated parent in a commit.' \
 353    'commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) &&
 354     parent=$(git show --pretty=raw $commit2 |
 355         sed -n -e "s/^parent //p" -e "/^author /q" |
 356         sort -u) &&
 357     test "z$commit0" = "z$parent" &&
 358     numparent=$(git show --pretty=raw $commit2 |
 359         sed -n -e "s/^parent //p" -e "/^author /q" |
 360         wc -l) &&
 361     test $numparent = 1'
 362
 363test_expect_success 'update-index D/F conflict' '
 364        mv path0 tmp &&
 365        mv path2 path0 &&
 366        mv tmp path2 &&
 367        git update-index --add --replace path2 path0/file2 &&
 368        numpath0=$(git ls-files path0 | wc -l) &&
 369        test $numpath0 = 1
 370'
 371
 372test_expect_success SYMLINKS 'absolute path works as expected' '
 373        mkdir first &&
 374        ln -s ../.git first/.git &&
 375        mkdir second &&
 376        ln -s ../first second/other &&
 377        mkdir third &&
 378        dir="$(cd .git; pwd -P)" &&
 379        dir2=third/../second/other/.git &&
 380        test "$dir" = "$(test-path-utils make_absolute_path $dir2)" &&
 381        file="$dir"/index &&
 382        test "$file" = "$(test-path-utils make_absolute_path $dir2/index)" &&
 383        basename=blub &&
 384        test "$dir/$basename" = "$(cd .git && test-path-utils make_absolute_path "$basename")" &&
 385        ln -s ../first/file .git/syml &&
 386        sym="$(cd first; pwd -P)"/file &&
 387        test "$sym" = "$(test-path-utils make_absolute_path "$dir2/syml")"
 388'
 389
 390test_expect_success 'very long name in the index handled sanely' '
 391
 392        a=a && # 1
 393        a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 16
 394        a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 256
 395        a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 4096
 396        a=${a}q &&
 397
 398        >path4 &&
 399        git update-index --add path4 &&
 400        (
 401                git ls-files -s path4 |
 402                sed -e "s/      .*/     /" |
 403                tr -d "\012"
 404                echo "$a"
 405        ) | git update-index --index-info &&
 406        len=$(git ls-files "a*" | wc -c) &&
 407        test $len = 4098
 408'
 409
 410test_done