2276e4e6b66b5bb6bb0efef310d3cf1c6d7494df
   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 'check result of "add -N"' '
  29        git ls-files -s file >actual &&
  30        empty=$(git hash-object --stdin </dev/null) &&
  31        echo "100644 $empty 0   file" >expect &&
  32        test_cmp expect actual
  33'
  34
  35test_expect_success 'intent to add is just an ordinary empty blob' '
  36        git add -u &&
  37        git ls-files -s file >actual &&
  38        git ls-files -s elif | sed -e "s/elif/file/" >expect &&
  39        test_cmp expect actual
  40'
  41
  42test_expect_success 'intent to add does not clobber existing paths' '
  43        git add -N file elif &&
  44        empty=$(git hash-object --stdin </dev/null) &&
  45        git ls-files -s >actual &&
  46        ! grep "$empty" actual
  47'
  48
  49test_expect_success 'i-t-a entry is simply ignored' '
  50        test_tick &&
  51        git commit -a -m initial &&
  52        git reset --hard &&
  53
  54        echo xyzzy >rezrov &&
  55        echo frotz >nitfol &&
  56        git add rezrov &&
  57        git add -N nitfol &&
  58        git commit -m second &&
  59        test $(git ls-tree HEAD -- nitfol | wc -l) = 0 &&
  60        test $(git diff --name-only HEAD -- nitfol | wc -l) = 1
  61'
  62
  63test_expect_success 'can commit with an unrelated i-t-a entry in index' '
  64        git reset --hard &&
  65        echo bozbar >rezrov &&
  66        echo frotz >nitfol &&
  67        git add rezrov &&
  68        git add -N nitfol &&
  69        git commit -m partial rezrov
  70'
  71
  72test_expect_success 'can "commit -a" with an i-t-a entry' '
  73        git reset --hard &&
  74        : >nitfol &&
  75        git add -N nitfol &&
  76        git commit -a -m all
  77'
  78
  79test_expect_success 'cache-tree invalidates i-t-a paths' '
  80        git reset --hard &&
  81        mkdir dir &&
  82        : >dir/foo &&
  83        git add dir/foo &&
  84        git commit -m foo &&
  85
  86        : >dir/bar &&
  87        git add -N dir/bar &&
  88        git diff --cached --name-only >actual &&
  89        echo dir/bar >expect &&
  90        test_cmp expect actual &&
  91
  92        git write-tree >/dev/null &&
  93
  94        git diff --cached --name-only >actual &&
  95        echo dir/bar >expect &&
  96        test_cmp expect actual
  97'
  98
  99test_expect_success 'cache-tree does not ignore dir that has i-t-a entries' '
 100        git init ita-in-dir &&
 101        (
 102                cd ita-in-dir &&
 103                mkdir 2 &&
 104                for f in 1 2/1 2/2 3
 105                do
 106                        echo "$f" >"$f"
 107                done &&
 108                git add 1 2/2 3 &&
 109                git add -N 2/1 &&
 110                git commit -m committed &&
 111                git ls-tree -r HEAD >actual &&
 112                grep 2/2 actual
 113        )
 114'
 115
 116test_expect_success 'cache-tree does skip dir that becomes empty' '
 117        rm -fr ita-in-dir &&
 118        git init ita-in-dir &&
 119        (
 120                cd ita-in-dir &&
 121                mkdir -p 1/2/3 &&
 122                echo 4 >1/2/3/4 &&
 123                git add -N 1/2/3/4 &&
 124                git write-tree >actual &&
 125                echo $EMPTY_TREE >expected &&
 126                test_cmp expected actual
 127        )
 128'
 129
 130test_done
 131