t / t1011-read-tree-sparse-checkout.shon commit format-patch: wrap long header lines (a1f6baa)
   1#!/bin/sh
   2
   3test_description='sparse checkout tests
   4
   5* (tag: removed, master) removed
   6| D     sub/added
   7* (HEAD, tag: top) modified and added
   8| M     init.t
   9| A     sub/added
  10* (tag: init) init
  11  A     init.t
  12'
  13
  14. ./test-lib.sh
  15
  16test_expect_success 'setup' '
  17        cat >expected <<-\EOF &&
  18        100644 77f0ba1734ed79d12881f81b36ee134de6a3327b 0       init.t
  19        100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0       sub/added
  20        100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0       subsub/added
  21        EOF
  22        cat >expected.swt <<-\EOF &&
  23        H init.t
  24        H sub/added
  25        H subsub/added
  26        EOF
  27
  28        test_commit init &&
  29        echo modified >>init.t &&
  30        mkdir sub subsub &&
  31        touch sub/added subsub/added &&
  32        git add init.t sub/added subsub/added &&
  33        git commit -m "modified and added" &&
  34        git tag top &&
  35        git rm sub/added &&
  36        git commit -m removed &&
  37        git tag removed &&
  38        git checkout top &&
  39        git ls-files --stage >result &&
  40        test_cmp expected result
  41'
  42
  43test_expect_success 'read-tree without .git/info/sparse-checkout' '
  44        git read-tree -m -u HEAD &&
  45        git ls-files --stage >result &&
  46        test_cmp expected result &&
  47        git ls-files -t >result &&
  48        test_cmp expected.swt result
  49'
  50
  51test_expect_success 'read-tree with .git/info/sparse-checkout but disabled' '
  52        echo >.git/info/sparse-checkout &&
  53        git read-tree -m -u HEAD &&
  54        git ls-files -t >result &&
  55        test_cmp expected.swt result &&
  56        test -f init.t &&
  57        test -f sub/added
  58'
  59
  60test_expect_success 'read-tree --no-sparse-checkout with empty .git/info/sparse-checkout and enabled' '
  61        git config core.sparsecheckout true &&
  62        echo >.git/info/sparse-checkout &&
  63        git read-tree --no-sparse-checkout -m -u HEAD &&
  64        git ls-files -t >result &&
  65        test_cmp expected.swt result &&
  66        test -f init.t &&
  67        test -f sub/added
  68'
  69
  70test_expect_success 'read-tree with empty .git/info/sparse-checkout' '
  71        git config core.sparsecheckout true &&
  72        echo >.git/info/sparse-checkout &&
  73        test_must_fail git read-tree -m -u HEAD &&
  74        git ls-files --stage >result &&
  75        test_cmp expected result &&
  76        git ls-files -t >result &&
  77        test_cmp expected.swt result &&
  78        test -f init.t &&
  79        test -f sub/added
  80'
  81
  82test_expect_success 'match directories with trailing slash' '
  83        cat >expected.swt-noinit <<-\EOF &&
  84        S init.t
  85        H sub/added
  86        S subsub/added
  87        EOF
  88
  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-noinit result &&
  93        test ! -f init.t &&
  94        test -f sub/added
  95'
  96
  97test_expect_success 'match directories without trailing slash' '
  98        echo sub >>.git/info/sparse-checkout &&
  99        git read-tree -m -u HEAD &&
 100        git ls-files -t >result &&
 101        test_cmp expected.swt-noinit result &&
 102        test ! -f init.t &&
 103        test -f sub/added
 104'
 105
 106test_expect_success 'match directory pattern' '
 107        echo "s?b" >>.git/info/sparse-checkout &&
 108        git read-tree -m -u HEAD &&
 109        git ls-files -t >result &&
 110        test_cmp expected.swt-noinit result &&
 111        test ! -f init.t &&
 112        test -f sub/added
 113'
 114
 115test_expect_success 'checkout area changes' '
 116        cat >expected.swt-nosub <<-\EOF &&
 117        H init.t
 118        S sub/added
 119        S subsub/added
 120        EOF
 121
 122        echo init.t >.git/info/sparse-checkout &&
 123        git read-tree -m -u HEAD &&
 124        git ls-files -t >result &&
 125        test_cmp expected.swt-nosub result &&
 126        test -f init.t &&
 127        test ! -f sub/added
 128'
 129
 130test_expect_success 'read-tree updates worktree, absent case' '
 131        echo sub/added >.git/info/sparse-checkout &&
 132        git checkout -f top &&
 133        git read-tree -m -u HEAD^ &&
 134        test ! -f init.t
 135'
 136
 137test_expect_success 'read-tree updates worktree, dirty case' '
 138        echo sub/added >.git/info/sparse-checkout &&
 139        git checkout -f top &&
 140        echo dirty >init.t &&
 141        git read-tree -m -u HEAD^ &&
 142        grep -q dirty init.t &&
 143        rm init.t
 144'
 145
 146test_expect_success 'read-tree removes worktree, dirty case' '
 147        echo init.t >.git/info/sparse-checkout &&
 148        git checkout -f top &&
 149        echo dirty >added &&
 150        git read-tree -m -u HEAD^ &&
 151        grep -q dirty added
 152'
 153
 154test_expect_success 'read-tree adds to worktree, absent case' '
 155        echo init.t >.git/info/sparse-checkout &&
 156        git checkout -f removed &&
 157        git read-tree -u -m HEAD^ &&
 158        test ! -f sub/added
 159'
 160
 161test_expect_success 'read-tree adds to worktree, dirty case' '
 162        echo init.t >.git/info/sparse-checkout &&
 163        git checkout -f removed &&
 164        mkdir sub &&
 165        echo dirty >sub/added &&
 166        git read-tree -u -m HEAD^ &&
 167        grep -q dirty sub/added
 168'
 169
 170test_expect_success 'index removal and worktree narrowing at the same time' '
 171        >empty &&
 172        echo init.t >.git/info/sparse-checkout &&
 173        echo sub/added >>.git/info/sparse-checkout &&
 174        git checkout -f top &&
 175        echo init.t >.git/info/sparse-checkout &&
 176        git checkout removed &&
 177        git ls-files sub/added >result &&
 178        test ! -f sub/added &&
 179        test_cmp empty result
 180'
 181
 182test_expect_success 'read-tree --reset removes outside worktree' '
 183        >empty &&
 184        echo init.t >.git/info/sparse-checkout &&
 185        git checkout -f top &&
 186        git reset --hard removed &&
 187        git ls-files sub/added >result &&
 188        test_cmp empty result
 189'
 190
 191test_done