t / t1011-read-tree-sparse-checkout.shon commit Change remote tracking to remote-tracking in non-trivial places (60109d0)
   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        EOF
  21        cat >expected.swt <<-\EOF &&
  22        H init.t
  23        H sub/added
  24        EOF
  25
  26        test_commit init &&
  27        echo modified >>init.t &&
  28        mkdir sub &&
  29        touch sub/added &&
  30        git add init.t sub/added &&
  31        git commit -m "modified and added" &&
  32        git tag top &&
  33        git rm sub/added &&
  34        git commit -m removed &&
  35        git tag removed &&
  36        git checkout top &&
  37        git ls-files --stage >result &&
  38        test_cmp expected result
  39'
  40
  41test_expect_success 'read-tree without .git/info/sparse-checkout' '
  42        git read-tree -m -u HEAD &&
  43        git ls-files --stage >result &&
  44        test_cmp expected result &&
  45        git ls-files -t >result &&
  46        test_cmp expected.swt result
  47'
  48
  49test_expect_success 'read-tree with .git/info/sparse-checkout but disabled' '
  50        echo >.git/info/sparse-checkout
  51        git read-tree -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 --no-sparse-checkout with empty .git/info/sparse-checkout and enabled' '
  59        git config core.sparsecheckout true &&
  60        echo >.git/info/sparse-checkout &&
  61        git read-tree --no-sparse-checkout -m -u HEAD &&
  62        git ls-files -t >result &&
  63        test_cmp expected.swt result &&
  64        test -f init.t &&
  65        test -f sub/added
  66'
  67
  68test_expect_success 'read-tree with empty .git/info/sparse-checkout' '
  69        git config core.sparsecheckout true &&
  70        echo >.git/info/sparse-checkout &&
  71        test_must_fail git read-tree -m -u HEAD &&
  72        git ls-files --stage >result &&
  73        test_cmp expected result &&
  74        git ls-files -t >result &&
  75        test_cmp expected.swt result &&
  76        test -f init.t &&
  77        test -f sub/added
  78'
  79
  80test_expect_success 'match directories with trailing slash' '
  81        cat >expected.swt-noinit <<-\EOF &&
  82        S init.t
  83        H sub/added
  84        EOF
  85
  86        echo sub/ > .git/info/sparse-checkout &&
  87        git read-tree -m -u HEAD &&
  88        git ls-files -t > result &&
  89        test_cmp expected.swt-noinit result &&
  90        test ! -f init.t &&
  91        test -f sub/added
  92'
  93
  94test_expect_failure 'match directories without trailing slash' '
  95        echo init.t >.git/info/sparse-checkout &&
  96        echo sub >>.git/info/sparse-checkout &&
  97        git read-tree -m -u HEAD &&
  98        git ls-files -t >result &&
  99        test_cmp expected.swt result &&
 100        test ! -f init.t &&
 101        test -f sub/added
 102'
 103
 104test_expect_success 'checkout area changes' '
 105        cat >expected.swt-nosub <<-\EOF &&
 106        H init.t
 107        S sub/added
 108        EOF
 109
 110        echo init.t >.git/info/sparse-checkout &&
 111        git read-tree -m -u HEAD &&
 112        git ls-files -t >result &&
 113        test_cmp expected.swt-nosub result &&
 114        test -f init.t &&
 115        test ! -f sub/added
 116'
 117
 118test_expect_success 'read-tree updates worktree, absent case' '
 119        echo sub/added >.git/info/sparse-checkout &&
 120        git checkout -f top &&
 121        git read-tree -m -u HEAD^ &&
 122        test ! -f init.t
 123'
 124
 125test_expect_success 'read-tree updates worktree, dirty case' '
 126        echo sub/added >.git/info/sparse-checkout &&
 127        git checkout -f top &&
 128        echo dirty >init.t &&
 129        git read-tree -m -u HEAD^ &&
 130        grep -q dirty init.t &&
 131        rm init.t
 132'
 133
 134test_expect_success 'read-tree removes worktree, dirty case' '
 135        echo init.t >.git/info/sparse-checkout &&
 136        git checkout -f top &&
 137        echo dirty >added &&
 138        git read-tree -m -u HEAD^ &&
 139        grep -q dirty added
 140'
 141
 142test_expect_success 'read-tree adds to worktree, absent case' '
 143        echo init.t >.git/info/sparse-checkout &&
 144        git checkout -f removed &&
 145        git read-tree -u -m HEAD^ &&
 146        test ! -f sub/added
 147'
 148
 149test_expect_success 'read-tree adds to worktree, dirty case' '
 150        echo init.t >.git/info/sparse-checkout &&
 151        git checkout -f removed &&
 152        mkdir sub &&
 153        echo dirty >sub/added &&
 154        git read-tree -u -m HEAD^ &&
 155        grep -q dirty sub/added
 156'
 157
 158test_expect_success 'index removal and worktree narrowing at the same time' '
 159        >empty &&
 160        echo init.t >.git/info/sparse-checkout &&
 161        echo sub/added >>.git/info/sparse-checkout &&
 162        git checkout -f top &&
 163        echo init.t >.git/info/sparse-checkout &&
 164        git checkout removed &&
 165        git ls-files sub/added >result &&
 166        test ! -f sub/added &&
 167        test_cmp empty result
 168'
 169
 170test_expect_success 'read-tree --reset removes outside worktree' '
 171        >empty &&
 172        echo init.t >.git/info/sparse-checkout &&
 173        git checkout -f top &&
 174        git reset --hard removed &&
 175        git ls-files sub/added >result &&
 176        test_cmp empty result
 177'
 178
 179test_done