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