t / t2201-add-update-typechange.shon commit Merge branch 'jc/unpack-trees' (7551391)
   1#!/bin/sh
   2
   3test_description='more git add -u'
   4
   5. ./test-lib.sh
   6
   7_z40=0000000000000000000000000000000000000000
   8
   9test_expect_success setup '
  10        >xyzzy &&
  11        _empty=$(git hash-object --stdin <xyzzy) &&
  12        >yomin &&
  13        >caskly &&
  14        if test_have_prereq SYMLINKS; then
  15                ln -s frotz nitfol &&
  16                T_letter=T
  17        else
  18                printf %s frotz > nitfol &&
  19                T_letter=M
  20        fi &&
  21        mkdir rezrov &&
  22        >rezrov/bozbar &&
  23        git add caskly xyzzy yomin nitfol rezrov/bozbar &&
  24
  25        test_tick &&
  26        git commit -m initial
  27
  28'
  29
  30test_expect_success modify '
  31        rm -f xyzzy yomin nitfol caskly &&
  32        # caskly disappears (not a submodule)
  33        mkdir caskly &&
  34        # nitfol changes from symlink to regular
  35        >nitfol &&
  36        # rezrov/bozbar disappears
  37        rm -fr rezrov &&
  38        if test_have_prereq SYMLINKS; then
  39                ln -s xyzzy rezrov
  40        else
  41                printf %s xyzzy > rezrov
  42        fi &&
  43        # xyzzy disappears (not a submodule)
  44        mkdir xyzzy &&
  45        echo gnusto >xyzzy/bozbar &&
  46        # yomin gets replaced with a submodule
  47        mkdir yomin &&
  48        >yomin/yomin &&
  49        (
  50                cd yomin &&
  51                git init &&
  52                git add yomin &&
  53                git commit -m "sub initial"
  54        ) &&
  55        yomin=$(GIT_DIR=yomin/.git git rev-parse HEAD) &&
  56        # yonk is added and then turned into a submodule
  57        # this should appear as T in diff-files and as A in diff-index
  58        >yonk &&
  59        git add yonk &&
  60        rm -f yonk &&
  61        mkdir yonk &&
  62        >yonk/yonk &&
  63        (
  64                cd yonk &&
  65                git init &&
  66                git add yonk &&
  67                git commit -m "sub initial"
  68        ) &&
  69        yonk=$(GIT_DIR=yonk/.git git rev-parse HEAD) &&
  70        # zifmia is added and then removed
  71        # this should appear in diff-files but not in diff-index.
  72        >zifmia &&
  73        git add zifmia &&
  74        rm -f zifmia &&
  75        mkdir zifmia &&
  76        {
  77                git ls-tree -r HEAD |
  78                sed -e "s/^/:/" -e "
  79                        /       caskly/{
  80                                s/      caskly/ $_z40 D&/
  81                                s/blob/000000/
  82                        }
  83                        /       nitfol/{
  84                                s/      nitfol/ $_z40 $T_letter&/
  85                                s/blob/100644/
  86                        }
  87                        /       rezrov.bozbar/{
  88                                s/      rezrov.bozbar/ $_z40 D&/
  89                                s/blob/000000/
  90                        }
  91                        /       xyzzy/{
  92                                s/      xyzzy/ $_z40 D&/
  93                                s/blob/000000/
  94                        }
  95                        /       yomin/{
  96                            s/  yomin/ $_z40 T&/
  97                                s/blob/160000/
  98                        }
  99                "
 100        } >expect &&
 101        {
 102                cat expect
 103                echo ":100644 160000 $_empty $_z40 T    yonk"
 104                echo ":100644 000000 $_empty $_z40 D    zifmia"
 105        } >expect-files &&
 106        {
 107                cat expect
 108                echo ":000000 160000 $_z40 $_z40 A      yonk"
 109        } >expect-index &&
 110        {
 111                echo "100644 $_empty 0  nitfol"
 112                echo "160000 $yomin 0   yomin"
 113                echo "160000 $yonk 0    yonk"
 114        } >expect-final
 115'
 116
 117test_expect_success diff-files '
 118        git diff-files --raw >actual &&
 119        test_cmp expect-files actual
 120'
 121
 122test_expect_success diff-index '
 123        git diff-index --raw HEAD -- >actual &&
 124        test_cmp expect-index actual
 125'
 126
 127test_expect_success 'add -u' '
 128        rm -f ".git/saved-index" &&
 129        cp -p ".git/index" ".git/saved-index" &&
 130        git add -u &&
 131        git ls-files -s >actual &&
 132        test_cmp expect-final actual
 133'
 134
 135test_expect_success 'commit -a' '
 136        if test -f ".git/saved-index"
 137        then
 138                rm -f ".git/index" &&
 139                mv ".git/saved-index" ".git/index"
 140        fi &&
 141        git commit -m "second" -a &&
 142        git ls-files -s >actual &&
 143        test_cmp expect-final actual &&
 144        rm -f .git/index &&
 145        git read-tree HEAD &&
 146        git ls-files -s >actual &&
 147        test_cmp expect-final actual
 148'
 149
 150test_done