t / t4027-diff-submodule.shon commit Merge branch 'ab/subtree-doc' (c9e8c1a)
   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 $_z40 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) [.git/config]' '
 117        git config diff.ignoreSubmodules all &&
 118        git diff HEAD >actual &&
 119        ! test -s actual &&
 120        git config submodule.subname.ignore none &&
 121        git config 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 submodule.subname.ignore all &&
 127        git diff HEAD >actual2 &&
 128        ! test -s actual2 &&
 129        git config submodule.subname.ignore untracked &&
 130        git diff HEAD >actual3 &&
 131        sed -e "1,/^@@/d" actual3 >actual3.body &&
 132        expect_from_to >expect.body $subprev $subprev-dirty &&
 133        test_cmp expect.body actual3.body &&
 134        git config submodule.subname.ignore dirty &&
 135        git diff HEAD >actual4 &&
 136        ! test -s actual4 &&
 137        git diff HEAD --ignore-submodules=none >actual &&
 138        sed -e "1,/^@@/d" actual >actual.body &&
 139        expect_from_to >expect.body $subprev $subprev-dirty &&
 140        test_cmp expect.body actual.body &&
 141        git config --remove-section submodule.subname &&
 142        git config --unset diff.ignoreSubmodules
 143'
 144
 145test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match) [.gitmodules]' '
 146        git config diff.ignoreSubmodules dirty &&
 147        git diff HEAD >actual &&
 148        ! test -s actual &&
 149        git config --add -f .gitmodules submodule.subname.ignore none &&
 150        git config --add -f .gitmodules submodule.subname.path sub &&
 151        git diff HEAD >actual &&
 152        sed -e "1,/^@@/d" actual >actual.body &&
 153        expect_from_to >expect.body $subprev $subprev-dirty &&
 154        test_cmp expect.body actual.body &&
 155        git config -f .gitmodules submodule.subname.ignore all &&
 156        git config -f .gitmodules submodule.subname.path sub &&
 157        git diff HEAD >actual2 &&
 158        ! test -s actual2 &&
 159        git config -f .gitmodules submodule.subname.ignore untracked &&
 160        git diff HEAD >actual3 &&
 161        sed -e "1,/^@@/d" actual3 >actual3.body &&
 162        expect_from_to >expect.body $subprev $subprev-dirty &&
 163        test_cmp expect.body actual3.body &&
 164        git config -f .gitmodules submodule.subname.ignore dirty &&
 165        git diff HEAD >actual4 &&
 166        ! test -s actual4 &&
 167        git config submodule.subname.ignore none &&
 168        git config submodule.subname.path sub &&
 169        git diff HEAD >actual &&
 170        sed -e "1,/^@@/d" actual >actual.body &&
 171        expect_from_to >expect.body $subprev $subprev-dirty &&
 172        test_cmp expect.body actual.body &&
 173        git config --remove-section submodule.subname &&
 174        git config --remove-section -f .gitmodules submodule.subname &&
 175        git config --unset diff.ignoreSubmodules &&
 176        rm .gitmodules
 177'
 178
 179test_expect_success 'git diff HEAD with dirty submodule (index, refs match)' '
 180        (
 181                cd sub &&
 182                git reset --hard &&
 183                echo >>world &&
 184                git add world
 185        ) &&
 186        git diff HEAD >actual &&
 187        sed -e "1,/^@@/d" actual >actual.body &&
 188        expect_from_to >expect.body $subprev $subprev-dirty &&
 189        test_cmp expect.body actual.body
 190'
 191
 192test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match)' '
 193        (
 194                cd sub &&
 195                git reset --hard &&
 196                git clean -qfdx &&
 197                >cruft
 198        ) &&
 199        git diff HEAD >actual &&
 200        sed -e "1,/^@@/d" actual >actual.body &&
 201        expect_from_to >expect.body $subprev $subprev-dirty &&
 202        test_cmp expect.body actual.body &&
 203        git diff --ignore-submodules=all HEAD >actual2 &&
 204        ! test -s actual2 &&
 205        git diff --ignore-submodules=untracked HEAD >actual3 &&
 206        ! test -s actual3 &&
 207        git diff --ignore-submodules=dirty HEAD >actual4 &&
 208        ! test -s actual4
 209'
 210
 211test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match) [.git/config]' '
 212        git config submodule.subname.ignore all &&
 213        git config submodule.subname.path sub &&
 214        git diff HEAD >actual2 &&
 215        ! test -s actual2 &&
 216        git config submodule.subname.ignore untracked &&
 217        git diff HEAD >actual3 &&
 218        ! test -s actual3 &&
 219        git config submodule.subname.ignore dirty &&
 220        git diff HEAD >actual4 &&
 221        ! test -s actual4 &&
 222        git diff --ignore-submodules=none HEAD >actual &&
 223        sed -e "1,/^@@/d" actual >actual.body &&
 224        expect_from_to >expect.body $subprev $subprev-dirty &&
 225        test_cmp expect.body actual.body &&
 226        git config --remove-section submodule.subname
 227'
 228
 229test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match) [.gitmodules]' '
 230        git config --add -f .gitmodules submodule.subname.ignore all &&
 231        git config --add -f .gitmodules submodule.subname.path sub &&
 232        git diff HEAD >actual2 &&
 233        ! test -s actual2 &&
 234        git config -f .gitmodules submodule.subname.ignore untracked &&
 235        git diff HEAD >actual3 &&
 236        ! test -s actual3 &&
 237        git config -f .gitmodules submodule.subname.ignore dirty &&
 238        git diff HEAD >actual4 &&
 239        ! test -s actual4 &&
 240        git config submodule.subname.ignore none &&
 241        git config submodule.subname.path sub &&
 242        git diff HEAD >actual &&
 243        sed -e "1,/^@@/d" actual >actual.body &&
 244        expect_from_to >expect.body $subprev $subprev-dirty &&
 245        test_cmp expect.body actual.body &&
 246        git config --remove-section submodule.subname &&
 247        git config --remove-section -f .gitmodules submodule.subname &&
 248        rm .gitmodules
 249'
 250
 251test_expect_success 'git diff between submodule commits' '
 252        git diff HEAD^..HEAD >actual &&
 253        sed -e "1,/^@@/d" actual >actual.body &&
 254        expect_from_to >expect.body $subtip $subprev &&
 255        test_cmp expect.body actual.body &&
 256        git diff --ignore-submodules=dirty HEAD^..HEAD >actual &&
 257        sed -e "1,/^@@/d" actual >actual.body &&
 258        expect_from_to >expect.body $subtip $subprev &&
 259        test_cmp expect.body actual.body &&
 260        git diff --ignore-submodules HEAD^..HEAD >actual &&
 261        ! test -s actual
 262'
 263
 264test_expect_success 'git diff between submodule commits [.git/config]' '
 265        git diff HEAD^..HEAD >actual &&
 266        sed -e "1,/^@@/d" actual >actual.body &&
 267        expect_from_to >expect.body $subtip $subprev &&
 268        test_cmp expect.body actual.body &&
 269        git config submodule.subname.ignore dirty &&
 270        git config submodule.subname.path sub &&
 271        git diff HEAD^..HEAD >actual &&
 272        sed -e "1,/^@@/d" actual >actual.body &&
 273        expect_from_to >expect.body $subtip $subprev &&
 274        test_cmp expect.body actual.body &&
 275        git config submodule.subname.ignore all &&
 276        git diff HEAD^..HEAD >actual &&
 277        ! test -s actual &&
 278        git diff --ignore-submodules=dirty HEAD^..HEAD >actual &&
 279        sed -e "1,/^@@/d" actual >actual.body &&
 280        expect_from_to >expect.body $subtip $subprev &&
 281        git config --remove-section submodule.subname
 282'
 283
 284test_expect_success 'git diff between submodule commits [.gitmodules]' '
 285        git diff HEAD^..HEAD >actual &&
 286        sed -e "1,/^@@/d" actual >actual.body &&
 287        expect_from_to >expect.body $subtip $subprev &&
 288        test_cmp expect.body actual.body &&
 289        git config --add -f .gitmodules submodule.subname.ignore dirty &&
 290        git config --add -f .gitmodules submodule.subname.path sub &&
 291        git diff HEAD^..HEAD >actual &&
 292        sed -e "1,/^@@/d" actual >actual.body &&
 293        expect_from_to >expect.body $subtip $subprev &&
 294        test_cmp expect.body actual.body &&
 295        git config -f .gitmodules submodule.subname.ignore all &&
 296        git diff HEAD^..HEAD >actual &&
 297        ! test -s actual &&
 298        git config submodule.subname.ignore dirty &&
 299        git config submodule.subname.path sub &&
 300        git diff  HEAD^..HEAD >actual &&
 301        sed -e "1,/^@@/d" actual >actual.body &&
 302        expect_from_to >expect.body $subtip $subprev &&
 303        git config --remove-section submodule.subname &&
 304        git config --remove-section -f .gitmodules submodule.subname &&
 305        rm .gitmodules
 306'
 307
 308test_expect_success 'git diff (empty submodule dir)' '
 309        : >empty &&
 310        rm -rf sub/* sub/.git &&
 311        git diff > actual.empty &&
 312        test_cmp empty actual.empty
 313'
 314
 315test_expect_success 'conflicted submodule setup' '
 316
 317        # 39 efs
 318        c=fffffffffffffffffffffffffffffffffffffff &&
 319        (
 320                echo "000000 $_z40 0    sub" &&
 321                echo "160000 1$c 1      sub" &&
 322                echo "160000 2$c 2      sub" &&
 323                echo "160000 3$c 3      sub"
 324        ) | git update-index --index-info &&
 325        echo >expect.nosub '\''diff --cc sub
 326index 2ffffff,3ffffff..0000000
 327--- a/sub
 328+++ b/sub
 329@@@ -1,1 -1,1 +1,1 @@@
 330- Subproject commit 2fffffffffffffffffffffffffffffffffffffff
 331 -Subproject commit 3fffffffffffffffffffffffffffffffffffffff
 332++Subproject commit 0000000000000000000000000000000000000000'\'' &&
 333
 334        hh=$(git rev-parse HEAD) &&
 335        sed -e "s/$_z40/$hh/" expect.nosub >expect.withsub
 336
 337'
 338
 339test_expect_success 'combined (empty submodule)' '
 340        rm -fr sub && mkdir sub &&
 341        git diff >actual &&
 342        test_cmp expect.nosub actual
 343'
 344
 345test_expect_success 'combined (with submodule)' '
 346        rm -fr sub &&
 347        git clone --no-checkout . sub &&
 348        git diff >actual &&
 349        test_cmp expect.withsub actual
 350'
 351
 352
 353
 354test_done