t / t1011-read-tree-sparse-checkout.shon commit test-lib: tests skipped by GIT_SKIP_TESTS say so (ef2ac68)
   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. "$TEST_DIRECTORY"/lib-read-tree.sh
  16
  17test_expect_success 'setup' '
  18        cat >expected <<-\EOF &&
  19        100644 77f0ba1734ed79d12881f81b36ee134de6a3327b 0       init.t
  20        100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0       sub/added
  21        100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0       sub/addedtoo
  22        100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0       subsub/added
  23        EOF
  24        cat >expected.swt <<-\EOF &&
  25        H init.t
  26        H sub/added
  27        H sub/addedtoo
  28        H subsub/added
  29        EOF
  30
  31        test_commit init &&
  32        echo modified >>init.t &&
  33        mkdir sub subsub &&
  34        touch sub/added sub/addedtoo subsub/added &&
  35        git add init.t sub/added sub/addedtoo subsub/added &&
  36        git commit -m "modified and added" &&
  37        git tag top &&
  38        git rm sub/added &&
  39        git commit -m removed &&
  40        git tag removed &&
  41        git checkout top &&
  42        git ls-files --stage >result &&
  43        test_cmp expected result
  44'
  45
  46test_expect_success 'read-tree without .git/info/sparse-checkout' '
  47        read_tree_u_must_succeed -m -u HEAD &&
  48        git ls-files --stage >result &&
  49        test_cmp expected result &&
  50        git ls-files -t >result &&
  51        test_cmp expected.swt result
  52'
  53
  54test_expect_success 'read-tree with .git/info/sparse-checkout but disabled' '
  55        echo >.git/info/sparse-checkout &&
  56        read_tree_u_must_succeed -m -u HEAD &&
  57        git ls-files -t >result &&
  58        test_cmp expected.swt result &&
  59        test -f init.t &&
  60        test -f sub/added
  61'
  62
  63test_expect_success 'read-tree --no-sparse-checkout with empty .git/info/sparse-checkout and enabled' '
  64        git config core.sparsecheckout true &&
  65        echo >.git/info/sparse-checkout &&
  66        read_tree_u_must_succeed --no-sparse-checkout -m -u HEAD &&
  67        git ls-files -t >result &&
  68        test_cmp expected.swt result &&
  69        test -f init.t &&
  70        test -f sub/added
  71'
  72
  73test_expect_success 'read-tree with empty .git/info/sparse-checkout' '
  74        git config core.sparsecheckout true &&
  75        echo >.git/info/sparse-checkout &&
  76        read_tree_u_must_fail -m -u HEAD &&
  77        git ls-files --stage >result &&
  78        test_cmp expected result &&
  79        git ls-files -t >result &&
  80        test_cmp expected.swt result &&
  81        test -f init.t &&
  82        test -f sub/added
  83'
  84
  85test_expect_success 'match directories with trailing slash' '
  86        cat >expected.swt-noinit <<-\EOF &&
  87        S init.t
  88        H sub/added
  89        H sub/addedtoo
  90        S subsub/added
  91        EOF
  92
  93        echo sub/ > .git/info/sparse-checkout &&
  94        read_tree_u_must_succeed -m -u HEAD &&
  95        git ls-files -t > result &&
  96        test_cmp expected.swt-noinit result &&
  97        test ! -f init.t &&
  98        test -f sub/added
  99'
 100
 101test_expect_success 'match directories without trailing slash' '
 102        echo sub >.git/info/sparse-checkout &&
 103        read_tree_u_must_succeed -m -u HEAD &&
 104        git ls-files -t >result &&
 105        test_cmp expected.swt-noinit result &&
 106        test ! -f init.t &&
 107        test -f sub/added
 108'
 109
 110test_expect_success 'match directories with negated patterns' '
 111        cat >expected.swt-negation <<\EOF &&
 112S init.t
 113S sub/added
 114H sub/addedtoo
 115S subsub/added
 116EOF
 117
 118        cat >.git/info/sparse-checkout <<\EOF &&
 119sub
 120!sub/added
 121EOF
 122        git read-tree -m -u HEAD &&
 123        git ls-files -t >result &&
 124        test_cmp expected.swt-negation result &&
 125        test ! -f init.t &&
 126        test ! -f sub/added &&
 127        test -f sub/addedtoo
 128'
 129
 130test_expect_success 'match directories with negated patterns (2)' '
 131        cat >expected.swt-negation2 <<\EOF &&
 132H init.t
 133H sub/added
 134S sub/addedtoo
 135H subsub/added
 136EOF
 137
 138        cat >.git/info/sparse-checkout <<\EOF &&
 139/*
 140!sub
 141sub/added
 142EOF
 143        git read-tree -m -u HEAD &&
 144        git ls-files -t >result &&
 145        test_cmp expected.swt-negation2 result &&
 146        test -f init.t &&
 147        test -f sub/added &&
 148        test ! -f sub/addedtoo
 149'
 150
 151test_expect_success 'match directory pattern' '
 152        echo "s?b" >.git/info/sparse-checkout &&
 153        read_tree_u_must_succeed -m -u HEAD &&
 154        git ls-files -t >result &&
 155        test_cmp expected.swt-noinit result &&
 156        test ! -f init.t &&
 157        test -f sub/added
 158'
 159
 160test_expect_success 'checkout area changes' '
 161        cat >expected.swt-nosub <<-\EOF &&
 162        H init.t
 163        S sub/added
 164        S sub/addedtoo
 165        S subsub/added
 166        EOF
 167
 168        echo init.t >.git/info/sparse-checkout &&
 169        read_tree_u_must_succeed -m -u HEAD &&
 170        git ls-files -t >result &&
 171        test_cmp expected.swt-nosub result &&
 172        test -f init.t &&
 173        test ! -f sub/added
 174'
 175
 176test_expect_success 'read-tree updates worktree, absent case' '
 177        echo sub/added >.git/info/sparse-checkout &&
 178        git checkout -f top &&
 179        read_tree_u_must_succeed -m -u HEAD^ &&
 180        test ! -f init.t
 181'
 182
 183test_expect_success 'read-tree updates worktree, dirty case' '
 184        echo sub/added >.git/info/sparse-checkout &&
 185        git checkout -f top &&
 186        echo dirty >init.t &&
 187        read_tree_u_must_succeed -m -u HEAD^ &&
 188        grep -q dirty init.t &&
 189        rm init.t
 190'
 191
 192test_expect_success 'read-tree removes worktree, dirty case' '
 193        echo init.t >.git/info/sparse-checkout &&
 194        git checkout -f top &&
 195        echo dirty >added &&
 196        read_tree_u_must_succeed -m -u HEAD^ &&
 197        grep -q dirty added
 198'
 199
 200test_expect_success 'read-tree adds to worktree, absent case' '
 201        echo init.t >.git/info/sparse-checkout &&
 202        git checkout -f removed &&
 203        read_tree_u_must_succeed -u -m HEAD^ &&
 204        test ! -f sub/added
 205'
 206
 207test_expect_success 'read-tree adds to worktree, dirty case' '
 208        echo init.t >.git/info/sparse-checkout &&
 209        git checkout -f removed &&
 210        mkdir sub &&
 211        echo dirty >sub/added &&
 212        read_tree_u_must_succeed -u -m HEAD^ &&
 213        grep -q dirty sub/added
 214'
 215
 216test_expect_success 'index removal and worktree narrowing at the same time' '
 217        >empty &&
 218        echo init.t >.git/info/sparse-checkout &&
 219        echo sub/added >>.git/info/sparse-checkout &&
 220        git checkout -f top &&
 221        echo init.t >.git/info/sparse-checkout &&
 222        git checkout removed &&
 223        git ls-files sub/added >result &&
 224        test ! -f sub/added &&
 225        test_cmp empty result
 226'
 227
 228test_expect_success 'read-tree --reset removes outside worktree' '
 229        >empty &&
 230        echo init.t >.git/info/sparse-checkout &&
 231        git checkout -f top &&
 232        git reset --hard removed &&
 233        git ls-files sub/added >result &&
 234        test_cmp empty result
 235'
 236
 237test_expect_success 'print errors when failed to update worktree' '
 238        echo sub >.git/info/sparse-checkout &&
 239        git checkout -f init &&
 240        mkdir sub &&
 241        touch sub/added sub/addedtoo &&
 242        test_must_fail git checkout top 2>actual &&
 243        cat >expected <<\EOF &&
 244error: The following untracked working tree files would be overwritten by checkout:
 245        sub/added
 246        sub/addedtoo
 247Please move or remove them before you can switch branches.
 248Aborting
 249EOF
 250        test_cmp expected actual
 251'
 252
 253test_expect_success 'checkout without --ignore-skip-worktree-bits' '
 254        echo "*" >.git/info/sparse-checkout &&
 255        git checkout -f top &&
 256        test_path_is_file init.t &&
 257        echo sub >.git/info/sparse-checkout &&
 258        git checkout &&
 259        echo modified >> sub/added &&
 260        git checkout . &&
 261        test_path_is_missing init.t &&
 262        git diff --exit-code HEAD
 263'
 264
 265test_expect_success 'checkout with --ignore-skip-worktree-bits' '
 266        echo "*" >.git/info/sparse-checkout &&
 267        git checkout -f top &&
 268        test_path_is_file init.t &&
 269        echo sub >.git/info/sparse-checkout &&
 270        git checkout &&
 271        echo modified >> sub/added &&
 272        git checkout --ignore-skip-worktree-bits . &&
 273        test_path_is_file init.t &&
 274        git diff --exit-code HEAD
 275'
 276
 277test_done