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