t / t0090-cache-tree.shon commit Documentation: "git reset <tree-ish> <pathspec>" takes a tree-ish, not tree-sh (debecc5)
   1#!/bin/sh
   2
   3test_description="Test whether cache-tree is properly updated
   4
   5Tests whether various commands properly update and/or rewrite the
   6cache-tree extension.
   7"
   8 . ./test-lib.sh
   9
  10cmp_cache_tree () {
  11        test-dump-cache-tree >actual &&
  12        sed "s/$_x40/SHA/" <actual >filtered &&
  13        test_cmp "$1" filtered
  14}
  15
  16# We don't bother with actually checking the SHA1:
  17# test-dump-cache-tree already verifies that all existing data is
  18# correct.
  19test_shallow_cache_tree () {
  20        printf "SHA  (%d entries, 0 subtrees)\n" $(git ls-files|wc -l) >expect &&
  21        cmp_cache_tree expect
  22}
  23
  24test_invalid_cache_tree () {
  25        echo "invalid                                   (0 subtrees)" >expect &&
  26        printf "SHA #(ref)  (%d entries, 0 subtrees)\n" $(git ls-files|wc -l) >>expect &&
  27        cmp_cache_tree expect
  28}
  29
  30test_no_cache_tree () {
  31        : >expect &&
  32        cmp_cache_tree expect
  33}
  34
  35test_expect_failure 'initial commit has cache-tree' '
  36        test_commit foo &&
  37        test_shallow_cache_tree
  38'
  39
  40test_expect_success 'read-tree HEAD establishes cache-tree' '
  41        git read-tree HEAD &&
  42        test_shallow_cache_tree
  43'
  44
  45test_expect_success 'git-add invalidates cache-tree' '
  46        test_when_finished "git reset --hard; git read-tree HEAD" &&
  47        echo "I changed this file" > foo &&
  48        git add foo &&
  49        test_invalid_cache_tree
  50'
  51
  52test_expect_success 'update-index invalidates cache-tree' '
  53        test_when_finished "git reset --hard; git read-tree HEAD" &&
  54        echo "I changed this file" > foo &&
  55        git update-index --add foo &&
  56        test_invalid_cache_tree
  57'
  58
  59test_expect_success 'write-tree establishes cache-tree' '
  60        test-scrap-cache-tree &&
  61        git write-tree &&
  62        test_shallow_cache_tree
  63'
  64
  65test_expect_success 'test-scrap-cache-tree works' '
  66        git read-tree HEAD &&
  67        test-scrap-cache-tree &&
  68        test_no_cache_tree
  69'
  70
  71test_expect_success 'second commit has cache-tree' '
  72        test_commit bar &&
  73        test_shallow_cache_tree
  74'
  75
  76test_expect_success 'reset --hard gives cache-tree' '
  77        test-scrap-cache-tree &&
  78        git reset --hard &&
  79        test_shallow_cache_tree
  80'
  81
  82test_expect_success 'reset --hard without index gives cache-tree' '
  83        rm -f .git/index &&
  84        git reset --hard &&
  85        test_shallow_cache_tree
  86'
  87
  88test_expect_failure 'checkout gives cache-tree' '
  89        git checkout HEAD^ &&
  90        test_shallow_cache_tree
  91'
  92
  93test_done