t / t4027-diff-submodule.shon commit http-backend: allow empty CONTENT_LENGTH (574c513)
   1#!/bin/sh
   2
   3test_description='difference in submodules'
   4
   5. ./test-lib.sh
   6. "$TEST_DIRECTORY"/diff-lib.sh
   7
   8test_expect_success setup '
   9        test_tick &&
  10        test_create_repo sub &&
  11        (
  12                cd sub &&
  13                echo hello >world &&
  14                git add world &&
  15                git commit -m submodule
  16        ) &&
  17
  18        test_tick &&
  19        echo frotz >nitfol &&
  20        git add nitfol sub &&
  21        git commit -m superproject &&
  22
  23        (
  24                cd sub &&
  25                echo goodbye >world &&
  26                git add world &&
  27                git commit -m "submodule #2"
  28        ) &&
  29
  30        set x $(
  31                cd sub &&
  32                git rev-list HEAD
  33        ) &&
  34        echo ":160000 160000 $3 $ZERO_OID M     sub" >expect &&
  35        subtip=$3 subprev=$2
  36'
  37
  38test_expect_success 'git diff --raw HEAD' '
  39        git diff --raw --abbrev=40 HEAD >actual &&
  40        test_cmp expect actual
  41'
  42
  43test_expect_success 'git diff-index --raw HEAD' '
  44        git diff-index --raw HEAD >actual.index &&
  45        test_cmp expect actual.index
  46'
  47
  48test_expect_success 'git diff-files --raw' '
  49        git diff-files --raw >actual.files &&
  50        test_cmp expect actual.files
  51'
  52
  53expect_from_to () {
  54        printf "%sSubproject commit %s\n+Subproject commit %s\n" \
  55                "-" "$1" "$2"
  56}
  57
  58test_expect_success 'git diff HEAD' '
  59        git diff HEAD >actual &&
  60        sed -e "1,/^@@/d" actual >actual.body &&
  61        expect_from_to >expect.body $subtip $subprev &&
  62        test_cmp expect.body actual.body
  63'
  64
  65test_expect_success 'git diff HEAD with dirty submodule (work tree)' '
  66        echo >>sub/world &&
  67        git diff HEAD >actual &&
  68        sed -e "1,/^@@/d" actual >actual.body &&
  69        expect_from_to >expect.body $subtip $subprev-dirty &&
  70        test_cmp expect.body actual.body
  71'
  72
  73test_expect_success 'git diff HEAD with dirty submodule (index)' '
  74        (
  75                cd sub &&
  76                git reset --hard &&
  77                echo >>world &&
  78                git add world
  79        ) &&
  80        git diff HEAD >actual &&
  81        sed -e "1,/^@@/d" actual >actual.body &&
  82        expect_from_to >expect.body $subtip $subprev-dirty &&
  83        test_cmp expect.body actual.body
  84'
  85
  86test_expect_success 'git diff HEAD with dirty submodule (untracked)' '
  87        (
  88                cd sub &&
  89                git reset --hard &&
  90                git clean -qfdx &&
  91                >cruft
  92        ) &&
  93        git diff HEAD >actual &&
  94        sed -e "1,/^@@/d" actual >actual.body &&
  95        expect_from_to >expect.body $subtip $subprev-dirty &&
  96        test_cmp expect.body actual.body
  97'
  98
  99test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match)' '
 100        git commit -m "x" sub &&
 101        echo >>sub/world &&
 102        git diff HEAD >actual &&
 103        sed -e "1,/^@@/d" actual >actual.body &&
 104        expect_from_to >expect.body $subprev $subprev-dirty &&
 105        test_cmp expect.body actual.body &&
 106        git diff --ignore-submodules HEAD >actual2 &&
 107        ! test -s actual2 &&
 108        git diff --ignore-submodules=untracked HEAD >actual3 &&
 109        sed -e "1,/^@@/d" actual3 >actual3.body &&
 110        expect_from_to >expect.body $subprev $subprev-dirty &&
 111        test_cmp expect.body actual3.body &&
 112        git diff --ignore-submodules=dirty HEAD >actual4 &&
 113        ! test -s actual4
 114'
 115
 116test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match) [.gitmodules]' '
 117        git config diff.ignoreSubmodules dirty &&
 118        git diff HEAD >actual &&
 119        ! test -s actual &&
 120        git config --add -f .gitmodules submodule.subname.ignore none &&
 121        git config --add -f .gitmodules submodule.subname.path sub &&
 122        git diff HEAD >actual &&
 123        sed -e "1,/^@@/d" actual >actual.body &&
 124        expect_from_to >expect.body $subprev $subprev-dirty &&
 125        test_cmp expect.body actual.body &&
 126        git config -f .gitmodules submodule.subname.ignore all &&
 127        git config -f .gitmodules submodule.subname.path sub &&
 128        git diff HEAD >actual2 &&
 129        ! test -s actual2 &&
 130        git config -f .gitmodules submodule.subname.ignore untracked &&
 131        git diff HEAD >actual3 &&
 132        sed -e "1,/^@@/d" actual3 >actual3.body &&
 133        expect_from_to >expect.body $subprev $subprev-dirty &&
 134        test_cmp expect.body actual3.body &&
 135        git config -f .gitmodules submodule.subname.ignore dirty &&
 136        git diff HEAD >actual4 &&
 137        ! test -s actual4 &&
 138        git config submodule.subname.ignore none &&
 139        git config submodule.subname.path sub &&
 140        git diff HEAD >actual &&
 141        sed -e "1,/^@@/d" actual >actual.body &&
 142        expect_from_to >expect.body $subprev $subprev-dirty &&
 143        test_cmp expect.body actual.body &&
 144        git config --remove-section submodule.subname &&
 145        git config --remove-section -f .gitmodules submodule.subname &&
 146        git config --unset diff.ignoreSubmodules &&
 147        rm .gitmodules
 148'
 149
 150test_expect_success 'git diff HEAD with dirty submodule (index, refs match)' '
 151        (
 152                cd sub &&
 153                git reset --hard &&
 154                echo >>world &&
 155                git add world
 156        ) &&
 157        git diff HEAD >actual &&
 158        sed -e "1,/^@@/d" actual >actual.body &&
 159        expect_from_to >expect.body $subprev $subprev-dirty &&
 160        test_cmp expect.body actual.body
 161'
 162
 163test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match)' '
 164        (
 165                cd sub &&
 166                git reset --hard &&
 167                git clean -qfdx &&
 168                >cruft
 169        ) &&
 170        git diff HEAD >actual &&
 171        sed -e "1,/^@@/d" actual >actual.body &&
 172        expect_from_to >expect.body $subprev $subprev-dirty &&
 173        test_cmp expect.body actual.body &&
 174        git diff --ignore-submodules=all HEAD >actual2 &&
 175        ! test -s actual2 &&
 176        git diff --ignore-submodules=untracked HEAD >actual3 &&
 177        ! test -s actual3 &&
 178        git diff --ignore-submodules=dirty HEAD >actual4 &&
 179        ! test -s actual4
 180'
 181
 182test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match) [.gitmodules]' '
 183        git config --add -f .gitmodules submodule.subname.ignore all &&
 184        git config --add -f .gitmodules submodule.subname.path sub &&
 185        git diff HEAD >actual2 &&
 186        ! test -s actual2 &&
 187        git config -f .gitmodules submodule.subname.ignore untracked &&
 188        git diff HEAD >actual3 &&
 189        ! test -s actual3 &&
 190        git config -f .gitmodules submodule.subname.ignore dirty &&
 191        git diff HEAD >actual4 &&
 192        ! test -s actual4 &&
 193        git config submodule.subname.ignore none &&
 194        git config submodule.subname.path sub &&
 195        git diff HEAD >actual &&
 196        sed -e "1,/^@@/d" actual >actual.body &&
 197        expect_from_to >expect.body $subprev $subprev-dirty &&
 198        test_cmp expect.body actual.body &&
 199        git config --remove-section submodule.subname &&
 200        git config --remove-section -f .gitmodules submodule.subname &&
 201        rm .gitmodules
 202'
 203
 204test_expect_success 'git diff between submodule commits' '
 205        git diff HEAD^..HEAD >actual &&
 206        sed -e "1,/^@@/d" actual >actual.body &&
 207        expect_from_to >expect.body $subtip $subprev &&
 208        test_cmp expect.body actual.body &&
 209        git diff --ignore-submodules=dirty HEAD^..HEAD >actual &&
 210        sed -e "1,/^@@/d" actual >actual.body &&
 211        expect_from_to >expect.body $subtip $subprev &&
 212        test_cmp expect.body actual.body &&
 213        git diff --ignore-submodules HEAD^..HEAD >actual &&
 214        ! test -s actual
 215'
 216
 217test_expect_success 'git diff between submodule commits [.gitmodules]' '
 218        git diff HEAD^..HEAD >actual &&
 219        sed -e "1,/^@@/d" actual >actual.body &&
 220        expect_from_to >expect.body $subtip $subprev &&
 221        test_cmp expect.body actual.body &&
 222        git config --add -f .gitmodules submodule.subname.ignore dirty &&
 223        git config --add -f .gitmodules submodule.subname.path sub &&
 224        git diff HEAD^..HEAD >actual &&
 225        sed -e "1,/^@@/d" actual >actual.body &&
 226        expect_from_to >expect.body $subtip $subprev &&
 227        test_cmp expect.body actual.body &&
 228        git config -f .gitmodules submodule.subname.ignore all &&
 229        git diff HEAD^..HEAD >actual &&
 230        ! test -s actual &&
 231        git config submodule.subname.ignore dirty &&
 232        git config submodule.subname.path sub &&
 233        git diff  HEAD^..HEAD >actual &&
 234        sed -e "1,/^@@/d" actual >actual.body &&
 235        expect_from_to >expect.body $subtip $subprev &&
 236        git config --remove-section submodule.subname &&
 237        git config --remove-section -f .gitmodules submodule.subname &&
 238        rm .gitmodules
 239'
 240
 241test_expect_success 'git diff (empty submodule dir)' '
 242        : >empty &&
 243        rm -rf sub/* sub/.git &&
 244        git diff > actual.empty &&
 245        test_cmp empty actual.empty
 246'
 247
 248test_expect_success 'conflicted submodule setup' '
 249
 250        # 39 efs
 251        c=fffffffffffffffffffffffffffffffffffffff &&
 252        (
 253                echo "000000 $ZERO_OID 0        sub" &&
 254                echo "160000 1$c 1      sub" &&
 255                echo "160000 2$c 2      sub" &&
 256                echo "160000 3$c 3      sub"
 257        ) | git update-index --index-info &&
 258        echo >expect.nosub '\''diff --cc sub
 259index 2ffffff,3ffffff..0000000
 260--- a/sub
 261+++ b/sub
 262@@@ -1,1 -1,1 +1,1 @@@
 263- Subproject commit 2fffffffffffffffffffffffffffffffffffffff
 264 -Subproject commit 3fffffffffffffffffffffffffffffffffffffff
 265++Subproject commit 0000000000000000000000000000000000000000'\'' &&
 266
 267        hh=$(git rev-parse HEAD) &&
 268        sed -e "s/$ZERO_OID/$hh/" expect.nosub >expect.withsub
 269
 270'
 271
 272test_expect_success 'combined (empty submodule)' '
 273        rm -fr sub && mkdir sub &&
 274        git diff >actual &&
 275        test_cmp expect.nosub actual
 276'
 277
 278test_expect_success 'combined (with submodule)' '
 279        rm -fr sub &&
 280        git clone --no-checkout . sub &&
 281        git diff >actual &&
 282        test_cmp expect.withsub actual
 283'
 284
 285
 286
 287test_done