| 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2008 Nguyễn Thái Ngọc Duy |
| 4 | # |
| 5 | |
| 6 | test_description='skip-worktree bit test' |
| 7 | |
| 8 | . ./test-lib.sh |
| 9 | |
| 10 | cat >expect.full <<EOF |
| 11 | H 1 |
| 12 | H 2 |
| 13 | H init.t |
| 14 | H sub/1 |
| 15 | H sub/2 |
| 16 | EOF |
| 17 | |
| 18 | cat >expect.skip <<EOF |
| 19 | S 1 |
| 20 | H 2 |
| 21 | H init.t |
| 22 | S sub/1 |
| 23 | H sub/2 |
| 24 | EOF |
| 25 | |
| 26 | setup_absent() { |
| 27 | test -f 1 && rm 1 |
| 28 | git update-index --remove 1 && |
| 29 | git update-index --add --cacheinfo 100644 $EMPTY_BLOB 1 && |
| 30 | git update-index --skip-worktree 1 |
| 31 | } |
| 32 | |
| 33 | test_absent() { |
| 34 | echo "100644 $EMPTY_BLOB 0 1" >expected && |
| 35 | git ls-files --stage 1 >result && |
| 36 | test_cmp expected result && |
| 37 | test ! -f 1 |
| 38 | } |
| 39 | |
| 40 | setup_dirty() { |
| 41 | git update-index --force-remove 1 && |
| 42 | echo dirty >1 && |
| 43 | git update-index --add --cacheinfo 100644 $EMPTY_BLOB 1 && |
| 44 | git update-index --skip-worktree 1 |
| 45 | } |
| 46 | |
| 47 | test_dirty() { |
| 48 | echo "100644 $EMPTY_BLOB 0 1" >expected && |
| 49 | git ls-files --stage 1 >result && |
| 50 | test_cmp expected result && |
| 51 | echo dirty >expected |
| 52 | test_cmp expected 1 |
| 53 | } |
| 54 | |
| 55 | test_expect_success 'setup' ' |
| 56 | test_commit init && |
| 57 | mkdir sub && |
| 58 | touch ./1 ./2 sub/1 sub/2 && |
| 59 | git add 1 2 sub/1 sub/2 && |
| 60 | git update-index --skip-worktree 1 sub/1 && |
| 61 | git ls-files -t >result && |
| 62 | test_cmp expect.skip result |
| 63 | ' |
| 64 | |
| 65 | test_expect_success 'update-index' ' |
| 66 | setup_absent && |
| 67 | git update-index 1 && |
| 68 | test_absent |
| 69 | ' |
| 70 | |
| 71 | test_expect_success 'update-index' ' |
| 72 | setup_dirty && |
| 73 | git update-index 1 && |
| 74 | test_dirty |
| 75 | ' |
| 76 | |
| 77 | test_expect_success 'update-index --remove' ' |
| 78 | setup_absent && |
| 79 | git update-index --remove 1 && |
| 80 | test -z "$(git ls-files 1)" && |
| 81 | test ! -f 1 |
| 82 | ' |
| 83 | |
| 84 | test_expect_success 'update-index --remove' ' |
| 85 | setup_dirty && |
| 86 | git update-index --remove 1 && |
| 87 | test -z "$(git ls-files 1)" && |
| 88 | echo dirty >expected && |
| 89 | test_cmp expected 1 |
| 90 | ' |
| 91 | |
| 92 | test_expect_success 'ls-files --deleted' ' |
| 93 | setup_absent && |
| 94 | test -z "$(git ls-files -d)" |
| 95 | ' |
| 96 | |
| 97 | test_expect_success 'ls-files --deleted' ' |
| 98 | setup_dirty && |
| 99 | test -z "$(git ls-files -d)" |
| 100 | ' |
| 101 | |
| 102 | test_expect_success 'ls-files --modified' ' |
| 103 | setup_absent && |
| 104 | test -z "$(git ls-files -m)" |
| 105 | ' |
| 106 | |
| 107 | test_expect_success 'ls-files --modified' ' |
| 108 | setup_dirty && |
| 109 | test -z "$(git ls-files -m)" |
| 110 | ' |
| 111 | |
| 112 | echo ":000000 100644 $ZERO_OID $EMPTY_BLOB A 1" >expected |
| 113 | test_expect_success 'diff-index does not examine skip-worktree absent entries' ' |
| 114 | setup_absent && |
| 115 | git diff-index HEAD -- 1 >result && |
| 116 | test_cmp expected result |
| 117 | ' |
| 118 | |
| 119 | test_expect_success 'diff-index does not examine skip-worktree dirty entries' ' |
| 120 | setup_dirty && |
| 121 | git diff-index HEAD -- 1 >result && |
| 122 | test_cmp expected result |
| 123 | ' |
| 124 | |
| 125 | test_expect_success 'diff-files does not examine skip-worktree absent entries' ' |
| 126 | setup_absent && |
| 127 | test -z "$(git diff-files -- one)" |
| 128 | ' |
| 129 | |
| 130 | test_expect_success 'diff-files does not examine skip-worktree dirty entries' ' |
| 131 | setup_dirty && |
| 132 | test -z "$(git diff-files -- one)" |
| 133 | ' |
| 134 | |
| 135 | test_expect_success 'commit on skip-worktree absent entries' ' |
| 136 | git reset && |
| 137 | setup_absent && |
| 138 | test_must_fail git commit -m null 1 |
| 139 | ' |
| 140 | |
| 141 | test_expect_success 'commit on skip-worktree dirty entries' ' |
| 142 | git reset && |
| 143 | setup_dirty && |
| 144 | test_must_fail git commit -m null 1 |
| 145 | ' |
| 146 | |
| 147 | test_done |