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