t / t1011-read-tree-sparse-checkout.shon commit Merge branch 'np/malloc-threading' (ea5f75a)
   1#!/bin/sh
   2
   3test_description='sparse checkout tests'
   4
   5. ./test-lib.sh
   6
   7cat >expected <<EOF
   8100644 77f0ba1734ed79d12881f81b36ee134de6a3327b 0       init.t
   9100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0       sub/added
  10EOF
  11test_expect_success 'setup' '
  12        test_commit init &&
  13        echo modified >> init.t &&
  14        mkdir sub &&
  15        touch sub/added &&
  16        git add init.t sub/added &&
  17        git commit -m "modified and added" &&
  18        git tag top &&
  19        git rm sub/added &&
  20        git commit -m removed &&
  21        git tag removed &&
  22        git checkout top &&
  23        git ls-files --stage > result &&
  24        test_cmp expected result
  25'
  26
  27cat >expected.swt <<EOF
  28H init.t
  29H sub/added
  30EOF
  31test_expect_success 'read-tree without .git/info/sparse-checkout' '
  32        git read-tree -m -u HEAD &&
  33        git ls-files --stage > result &&
  34        test_cmp expected result &&
  35        git ls-files -t > result &&
  36        test_cmp expected.swt result
  37'
  38
  39test_expect_success 'read-tree with .git/info/sparse-checkout but disabled' '
  40        echo > .git/info/sparse-checkout
  41        git read-tree -m -u HEAD &&
  42        git ls-files -t > result &&
  43        test_cmp expected.swt result &&
  44        test -f init.t &&
  45        test -f sub/added
  46'
  47
  48test_expect_success 'read-tree --no-sparse-checkout with empty .git/info/sparse-checkout and enabled' '
  49        git config core.sparsecheckout true &&
  50        echo > .git/info/sparse-checkout &&
  51        git read-tree --no-sparse-checkout -m -u HEAD &&
  52        git ls-files -t > result &&
  53        test_cmp expected.swt result &&
  54        test -f init.t &&
  55        test -f sub/added
  56'
  57
  58test_expect_success 'read-tree with empty .git/info/sparse-checkout' '
  59        git config core.sparsecheckout true &&
  60        echo > .git/info/sparse-checkout &&
  61        test_must_fail git read-tree -m -u HEAD &&
  62        git ls-files --stage > result &&
  63        test_cmp expected result &&
  64        git ls-files -t > result &&
  65        test_cmp expected.swt result &&
  66        test -f init.t &&
  67        test -f sub/added
  68'
  69
  70cat >expected.swt <<EOF
  71S init.t
  72H sub/added
  73EOF
  74test_expect_success 'match directories with trailing slash' '
  75        echo sub/ > .git/info/sparse-checkout &&
  76        git read-tree -m -u HEAD &&
  77        git ls-files -t > result &&
  78        test_cmp expected.swt result &&
  79        test ! -f init.t &&
  80        test -f sub/added
  81'
  82
  83cat >expected.swt <<EOF
  84H init.t
  85H sub/added
  86EOF
  87test_expect_failure 'match directories without trailing slash' '
  88        echo init.t > .git/info/sparse-checkout &&
  89        echo sub >> .git/info/sparse-checkout &&
  90        git read-tree -m -u HEAD &&
  91        git ls-files -t > result &&
  92        test_cmp expected.swt result &&
  93        test ! -f init.t &&
  94        test -f sub/added
  95'
  96
  97cat >expected.swt <<EOF
  98H init.t
  99S sub/added
 100EOF
 101test_expect_success 'checkout area changes' '
 102        echo init.t > .git/info/sparse-checkout &&
 103        git read-tree -m -u HEAD &&
 104        git ls-files -t > result &&
 105        test_cmp expected.swt result &&
 106        test -f init.t &&
 107        test ! -f sub/added
 108'
 109
 110test_expect_success 'read-tree updates worktree, absent case' '
 111        echo sub/added > .git/info/sparse-checkout &&
 112        git checkout -f top &&
 113        git read-tree -m -u HEAD^ &&
 114        test ! -f init.t
 115'
 116
 117test_expect_success 'read-tree updates worktree, dirty case' '
 118        echo sub/added > .git/info/sparse-checkout &&
 119        git checkout -f top &&
 120        echo dirty > init.t &&
 121        git read-tree -m -u HEAD^ &&
 122        grep -q dirty init.t &&
 123        rm init.t
 124'
 125
 126test_expect_success 'read-tree removes worktree, dirty case' '
 127        echo init.t > .git/info/sparse-checkout &&
 128        git checkout -f top &&
 129        echo dirty > added &&
 130        git read-tree -m -u HEAD^ &&
 131        grep -q dirty added
 132'
 133
 134test_expect_success 'read-tree adds to worktree, absent case' '
 135        echo init.t > .git/info/sparse-checkout &&
 136        git checkout -f removed &&
 137        git read-tree -u -m HEAD^ &&
 138        test ! -f sub/added
 139'
 140
 141test_expect_success 'read-tree adds to worktree, dirty case' '
 142        echo init.t > .git/info/sparse-checkout &&
 143        git checkout -f removed &&
 144        mkdir sub &&
 145        echo dirty > sub/added &&
 146        git read-tree -u -m HEAD^ &&
 147        grep -q dirty sub/added
 148'
 149
 150test_done