t / t2200-add-update.shon commit Merge branch 'tr/push-no-verify-doc' (3f261c0)
   1#!/bin/sh
   2
   3test_description='git add -u
   4
   5This test creates a working tree state with three files:
   6
   7  top (previously committed, modified)
   8  dir/sub (previously committed, modified)
   9  dir/other (untracked)
  10
  11and issues a git add -u with path limiting on "dir" to add
  12only the updates to dir/sub.
  13
  14Also tested are "git add -u" without limiting, and "git add -u"
  15without contents changes, and other conditions'
  16
  17. ./test-lib.sh
  18
  19test_expect_success setup '
  20        echo initial >check &&
  21        echo initial >top &&
  22        echo initial >foo &&
  23        mkdir dir1 dir2 &&
  24        echo initial >dir1/sub1 &&
  25        echo initial >dir1/sub2 &&
  26        echo initial >dir2/sub3 &&
  27        git add check dir1 dir2 top foo &&
  28        test_tick &&
  29        git commit -m initial &&
  30
  31        echo changed >check &&
  32        echo changed >top &&
  33        echo changed >dir2/sub3 &&
  34        rm -f dir1/sub1 &&
  35        echo other >dir2/other
  36'
  37
  38test_expect_success update '
  39        git add -u dir1 dir2
  40'
  41
  42test_expect_success 'update noticed a removal' '
  43        test "$(git ls-files dir1/sub1)" = ""
  44'
  45
  46test_expect_success 'update touched correct path' '
  47        test "$(git diff-files --name-status dir2/sub3)" = ""
  48'
  49
  50test_expect_success 'update did not touch other tracked files' '
  51        test "$(git diff-files --name-status check)" = "M       check" &&
  52        test "$(git diff-files --name-status top)" = "M top"
  53'
  54
  55test_expect_success 'update did not touch untracked files' '
  56        test "$(git ls-files dir2/other)" = ""
  57'
  58
  59test_expect_success 'cache tree has not been corrupted' '
  60
  61        git ls-files -s |
  62        sed -e "s/ 0    /       /" >expect &&
  63        git ls-tree -r $(git write-tree) |
  64        sed -e "s/ blob / /" >current &&
  65        test_cmp expect current
  66
  67'
  68
  69test_expect_success 'update from a subdirectory' '
  70        (
  71                cd dir1 &&
  72                echo more >sub2 &&
  73                git add -u sub2
  74        )
  75'
  76
  77test_expect_success 'change gets noticed' '
  78
  79        test "$(git diff-files --name-status dir1)" = ""
  80
  81'
  82
  83# Note that this is scheduled to change in Git 2.0, when
  84# "git add -u" will become full-tree by default.
  85test_expect_success 'non-limited update in subdir leaves root alone' '
  86        (
  87                cd dir1 &&
  88                echo even more >>sub2 &&
  89                git add -u
  90        ) &&
  91        cat >expect <<-\EOF &&
  92        check
  93        top
  94        EOF
  95        git diff-files --name-only >actual &&
  96        test_cmp expect actual
  97'
  98
  99test_expect_success SYMLINKS 'replace a file with a symlink' '
 100
 101        rm foo &&
 102        ln -s top foo &&
 103        git add -u -- foo
 104
 105'
 106
 107test_expect_success 'add everything changed' '
 108
 109        git add -u &&
 110        test -z "$(git diff-files)"
 111
 112'
 113
 114test_expect_success 'touch and then add -u' '
 115
 116        touch check &&
 117        git add -u &&
 118        test -z "$(git diff-files)"
 119
 120'
 121
 122test_expect_success 'touch and then add explicitly' '
 123
 124        touch check &&
 125        git add check &&
 126        test -z "$(git diff-files)"
 127
 128'
 129
 130test_expect_success 'add -n -u should not add but just report' '
 131
 132        (
 133                echo "add '\''check'\''" &&
 134                echo "remove '\''top'\''"
 135        ) >expect &&
 136        before=$(git ls-files -s check top) &&
 137        echo changed >>check &&
 138        rm -f top &&
 139        git add -n -u >actual &&
 140        after=$(git ls-files -s check top) &&
 141
 142        test "$before" = "$after" &&
 143        test_i18ncmp expect actual
 144
 145'
 146
 147test_expect_success 'add -u resolves unmerged paths' '
 148        git reset --hard &&
 149        one=$(echo 1 | git hash-object -w --stdin) &&
 150        two=$(echo 2 | git hash-object -w --stdin) &&
 151        three=$(echo 3 | git hash-object -w --stdin) &&
 152        {
 153                for path in path1 path2
 154                do
 155                        echo "100644 $one 1     $path"
 156                        echo "100644 $two 2     $path"
 157                        echo "100644 $three 3   $path"
 158                done
 159                echo "100644 $one 1     path3"
 160                echo "100644 $one 1     path4"
 161                echo "100644 $one 3     path5"
 162                echo "100644 $one 3     path6"
 163        } |
 164        git update-index --index-info &&
 165        echo 3 >path1 &&
 166        echo 2 >path3 &&
 167        echo 2 >path5 &&
 168
 169        # Fail to explicitly resolve removed paths with "git add"
 170        test_must_fail git add --no-all path4 &&
 171        test_must_fail git add --no-all path6 &&
 172
 173        # "add -u" should notice removals no matter what stages
 174        # the index entries are in.
 175        git add -u &&
 176        git ls-files -s path1 path2 path3 path4 path5 path6 >actual &&
 177        {
 178                echo "100644 $three 0   path1"
 179                echo "100644 $two 0     path3"
 180                echo "100644 $two 0     path5"
 181        } >expect &&
 182        test_cmp expect actual
 183'
 184
 185test_expect_success '"add -u non-existent" should fail' '
 186        test_must_fail git add -u non-existent &&
 187        ! (git ls-files | grep "non-existent")
 188'
 189
 190test_done