t / t2203-add-intent.shon commit Merge branch 'ab/commit-m-with-fixup' (5550449)
   1#!/bin/sh
   2
   3test_description='Intent to add'
   4
   5. ./test-lib.sh
   6
   7test_expect_success 'intent to add' '
   8        test_commit 1 &&
   9        git rm 1.t &&
  10        echo hello >1.t &&
  11        echo hello >file &&
  12        echo hello >elif &&
  13        git add -N file &&
  14        git add elif &&
  15        git add -N 1.t
  16'
  17
  18test_expect_success 'git status' '
  19        git status --porcelain | grep -v actual >actual &&
  20        cat >expect <<-\EOF &&
  21        DA 1.t
  22        A  elif
  23         A file
  24        EOF
  25        test_cmp expect actual
  26'
  27
  28test_expect_success 'git status with porcelain v2' '
  29        git status --porcelain=v2 | grep -v "^?" >actual &&
  30        nam1=d00491fd7e5bb6fa28c517a0bb32b8b506539d4d &&
  31        nam2=ce013625030ba8dba906f756967f9e9ca394464a &&
  32        cat >expect <<-EOF &&
  33        1 DA N... 100644 000000 100644 $nam1 $_z40 1.t
  34        1 A. N... 000000 100644 100644 $_z40 $nam2 elif
  35        1 .A N... 000000 000000 100644 $_z40 $_z40 file
  36        EOF
  37        test_cmp expect actual
  38'
  39
  40test_expect_success 'check result of "add -N"' '
  41        git ls-files -s file >actual &&
  42        empty=$(git hash-object --stdin </dev/null) &&
  43        echo "100644 $empty 0   file" >expect &&
  44        test_cmp expect actual
  45'
  46
  47test_expect_success 'intent to add is just an ordinary empty blob' '
  48        git add -u &&
  49        git ls-files -s file >actual &&
  50        git ls-files -s elif | sed -e "s/elif/file/" >expect &&
  51        test_cmp expect actual
  52'
  53
  54test_expect_success 'intent to add does not clobber existing paths' '
  55        git add -N file elif &&
  56        empty=$(git hash-object --stdin </dev/null) &&
  57        git ls-files -s >actual &&
  58        ! grep "$empty" actual
  59'
  60
  61test_expect_success 'i-t-a entry is simply ignored' '
  62        test_tick &&
  63        git commit -a -m initial &&
  64        git reset --hard &&
  65
  66        echo xyzzy >rezrov &&
  67        echo frotz >nitfol &&
  68        git add rezrov &&
  69        git add -N nitfol &&
  70        git commit -m second &&
  71        test $(git ls-tree HEAD -- nitfol | wc -l) = 0 &&
  72        test $(git diff --name-only HEAD -- nitfol | wc -l) = 1 &&
  73        test $(git diff --name-only --ita-invisible-in-index HEAD -- nitfol | wc -l) = 0 &&
  74        test $(git diff --name-only --ita-invisible-in-index -- nitfol | wc -l) = 1
  75'
  76
  77test_expect_success 'can commit with an unrelated i-t-a entry in index' '
  78        git reset --hard &&
  79        echo bozbar >rezrov &&
  80        echo frotz >nitfol &&
  81        git add rezrov &&
  82        git add -N nitfol &&
  83        git commit -m partial rezrov
  84'
  85
  86test_expect_success 'can "commit -a" with an i-t-a entry' '
  87        git reset --hard &&
  88        : >nitfol &&
  89        git add -N nitfol &&
  90        git commit -a -m all
  91'
  92
  93test_expect_success 'cache-tree invalidates i-t-a paths' '
  94        git reset --hard &&
  95        mkdir dir &&
  96        : >dir/foo &&
  97        git add dir/foo &&
  98        git commit -m foo &&
  99
 100        : >dir/bar &&
 101        git add -N dir/bar &&
 102        git diff --cached --name-only >actual &&
 103        echo dir/bar >expect &&
 104        test_cmp expect actual &&
 105
 106        git write-tree >/dev/null &&
 107
 108        git diff --cached --name-only >actual &&
 109        echo dir/bar >expect &&
 110        test_cmp expect actual
 111'
 112
 113test_expect_success 'cache-tree does not ignore dir that has i-t-a entries' '
 114        git init ita-in-dir &&
 115        (
 116                cd ita-in-dir &&
 117                mkdir 2 &&
 118                for f in 1 2/1 2/2 3
 119                do
 120                        echo "$f" >"$f"
 121                done &&
 122                git add 1 2/2 3 &&
 123                git add -N 2/1 &&
 124                git commit -m committed &&
 125                git ls-tree -r HEAD >actual &&
 126                grep 2/2 actual
 127        )
 128'
 129
 130test_expect_success 'cache-tree does skip dir that becomes empty' '
 131        rm -fr ita-in-dir &&
 132        git init ita-in-dir &&
 133        (
 134                cd ita-in-dir &&
 135                mkdir -p 1/2/3 &&
 136                echo 4 >1/2/3/4 &&
 137                git add -N 1/2/3/4 &&
 138                git write-tree >actual &&
 139                echo $EMPTY_TREE >expected &&
 140                test_cmp expected actual
 141        )
 142'
 143
 144test_expect_success 'commit: ita entries ignored in empty initial commit check' '
 145        git init empty-initial-commit &&
 146        (
 147                cd empty-initial-commit &&
 148                : >one &&
 149                git add -N one &&
 150                test_must_fail git commit -m nothing-new-here
 151        )
 152'
 153
 154test_expect_success 'commit: ita entries ignored in empty commit check' '
 155        git init empty-subsequent-commit &&
 156        (
 157                cd empty-subsequent-commit &&
 158                test_commit one &&
 159                : >two &&
 160                git add -N two &&
 161                test_must_fail git commit -m nothing-new-here
 162        )
 163'
 164
 165test_expect_success 'rename detection finds the right names' '
 166        git init rename-detection &&
 167        (
 168                cd rename-detection &&
 169                echo contents >first &&
 170                git add first &&
 171                git commit -m first &&
 172                mv first third &&
 173                git add -N third &&
 174
 175                git status | grep -v "^?" >actual.1 &&
 176                test_i18ngrep "renamed: *first -> third" actual.1 &&
 177
 178                git status --porcelain | grep -v "^?" >actual.2 &&
 179                cat >expected.2 <<-\EOF &&
 180                 R first -> third
 181                EOF
 182                test_cmp expected.2 actual.2 &&
 183
 184                hash=12f00e90b6ef79117ce6e650416b8cf517099b78 &&
 185                git status --porcelain=v2 | grep -v "^?" >actual.3 &&
 186                cat >expected.3 <<-EOF &&
 187                2 .R N... 100644 100644 100644 $hash $hash R100 third   first
 188                EOF
 189                test_cmp expected.3 actual.3
 190        )
 191'
 192
 193test_expect_success 'double rename detection in status' '
 194        git init rename-detection-2 &&
 195        (
 196                cd rename-detection-2 &&
 197                echo contents >first &&
 198                git add first &&
 199                git commit -m first &&
 200                git mv first second &&
 201                mv second third &&
 202                git add -N third &&
 203
 204                git status | grep -v "^?" >actual.1 &&
 205                test_i18ngrep "renamed: *first -> second" actual.1 &&
 206                test_i18ngrep "renamed: *second -> third" actual.1 &&
 207
 208                git status --porcelain | grep -v "^?" >actual.2 &&
 209                cat >expected.2 <<-\EOF &&
 210                R  first -> second
 211                 R second -> third
 212                EOF
 213                test_cmp expected.2 actual.2 &&
 214
 215                hash=12f00e90b6ef79117ce6e650416b8cf517099b78 &&
 216                git status --porcelain=v2 | grep -v "^?" >actual.3 &&
 217                cat >expected.3 <<-EOF &&
 218                2 R. N... 100644 100644 100644 $hash $hash R100 second  first
 219                2 .R N... 100644 100644 100644 $hash $hash R100 third   second
 220                EOF
 221                test_cmp expected.3 actual.3
 222        )
 223'
 224
 225test_done
 226