t / t7012-skip-worktree-writing.shon commit Merge branch 'jk/am-i-resolved-fix' into maint (5bbbd57)
   1#!/bin/sh
   2#
   3# Copyright (c) 2008 Nguyễn Thái Ngọc Duy
   4#
   5
   6test_description='test worktree writing operations when skip-worktree is used'
   7
   8. ./test-lib.sh
   9
  10test_expect_success 'setup' '
  11        test_commit init &&
  12        echo modified >> init.t &&
  13        touch added &&
  14        git add init.t added &&
  15        git commit -m "modified and added" &&
  16        git tag top
  17'
  18
  19test_expect_success 'read-tree updates worktree, absent case' '
  20        git checkout -f top &&
  21        git update-index --skip-worktree init.t &&
  22        rm init.t &&
  23        git read-tree -m -u HEAD^ &&
  24        echo init > expected &&
  25        test_cmp expected init.t
  26'
  27
  28test_expect_success 'read-tree updates worktree, dirty case' '
  29        git checkout -f top &&
  30        git update-index --skip-worktree init.t &&
  31        echo dirty >> init.t &&
  32        test_must_fail git read-tree -m -u HEAD^ &&
  33        grep -q dirty init.t &&
  34        test "$(git ls-files -t init.t)" = "S init.t" &&
  35        git update-index --no-skip-worktree init.t
  36'
  37
  38test_expect_success 'read-tree removes worktree, absent case' '
  39        git checkout -f top &&
  40        git update-index --skip-worktree added &&
  41        rm added &&
  42        git read-tree -m -u HEAD^ &&
  43        test ! -f added
  44'
  45
  46test_expect_success 'read-tree removes worktree, dirty case' '
  47        git checkout -f top &&
  48        git update-index --skip-worktree added &&
  49        echo dirty >> added &&
  50        test_must_fail git read-tree -m -u HEAD^ &&
  51        grep -q dirty added &&
  52        test "$(git ls-files -t added)" = "S added" &&
  53        git update-index --no-skip-worktree added
  54'
  55
  56setup_absent() {
  57        test -f 1 && rm 1
  58        git update-index --remove 1 &&
  59        git update-index --add --cacheinfo 100644 $EMPTY_BLOB 1 &&
  60        git update-index --skip-worktree 1
  61}
  62
  63test_absent() {
  64        echo "100644 $EMPTY_BLOB 0      1" > expected &&
  65        git ls-files --stage 1 > result &&
  66        test_cmp expected result &&
  67        test ! -f 1
  68}
  69
  70setup_dirty() {
  71        git update-index --force-remove 1 &&
  72        echo dirty > 1 &&
  73        git update-index --add --cacheinfo 100644 $EMPTY_BLOB 1 &&
  74        git update-index --skip-worktree 1
  75}
  76
  77test_dirty() {
  78        echo "100644 $EMPTY_BLOB 0      1" > expected &&
  79        git ls-files --stage 1 > result &&
  80        test_cmp expected result &&
  81        echo dirty > expected
  82        test_cmp expected 1
  83}
  84
  85cat >expected <<EOF
  86S 1
  87H 2
  88H init.t
  89S sub/1
  90H sub/2
  91EOF
  92
  93test_expect_success 'index setup' '
  94        git checkout -f init &&
  95        mkdir sub &&
  96        touch ./1 ./2 sub/1 sub/2 &&
  97        git add 1 2 sub/1 sub/2 &&
  98        git update-index --skip-worktree 1 sub/1 &&
  99        git ls-files -t > result &&
 100        test_cmp expected result
 101'
 102
 103test_expect_success 'git-add ignores worktree content' '
 104        setup_absent &&
 105        git add 1 &&
 106        test_absent
 107'
 108
 109test_expect_success 'git-add ignores worktree content' '
 110        setup_dirty &&
 111        git add 1 &&
 112        test_dirty
 113'
 114
 115test_expect_success 'git-rm fails if worktree is dirty' '
 116        setup_dirty &&
 117        test_must_fail git rm 1 &&
 118        test_dirty
 119'
 120
 121cat >expected <<EOF
 122Would remove expected
 123Would remove result
 124EOF
 125test_expect_success 'git-clean, absent case' '
 126        setup_absent &&
 127        git clean -n > result &&
 128        test_i18ncmp expected result
 129'
 130
 131test_expect_success 'git-clean, dirty case' '
 132        setup_dirty &&
 133        git clean -n > result &&
 134        test_i18ncmp expected result
 135'
 136
 137#TODO test_expect_failure 'git-apply adds file' false
 138#TODO test_expect_failure 'git-apply updates file' false
 139#TODO test_expect_failure 'git-apply removes file' false
 140#TODO test_expect_failure 'git-mv to skip-worktree' false
 141#TODO test_expect_failure 'git-mv from skip-worktree' false
 142#TODO test_expect_failure 'git-checkout' false
 143
 144test_done