t / t4027-diff-submodule.shon commit Merge branch 'js/merge-rr-fix' (4bd874c)
   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 (index, refs match)' '
 118        (
 119                cd sub &&
 120                git reset --hard &&
 121                echo >>world &&
 122                git add world
 123        ) &&
 124        git diff HEAD >actual &&
 125        sed -e "1,/^@@/d" actual >actual.body &&
 126        expect_from_to >expect.body $subprev $subprev-dirty &&
 127        test_cmp expect.body actual.body
 128'
 129
 130test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match)' '
 131        (
 132                cd sub &&
 133                git reset --hard &&
 134                git clean -qfdx &&
 135                >cruft
 136        ) &&
 137        git diff HEAD >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 diff --ignore-submodules=all HEAD >actual2 &&
 142        ! test -s actual2 &&
 143        git diff --ignore-submodules=untracked HEAD >actual3 &&
 144        ! test -s actual3 &&
 145        git diff --ignore-submodules=dirty HEAD >actual4 &&
 146        ! test -s actual4
 147'
 148
 149test_expect_success 'git diff (empty submodule dir)' '
 150        : >empty &&
 151        rm -rf sub/* sub/.git &&
 152        git diff > actual.empty &&
 153        test_cmp empty actual.empty
 154'
 155
 156test_expect_success 'conflicted submodule setup' '
 157
 158        # 39 efs
 159        c=fffffffffffffffffffffffffffffffffffffff
 160        (
 161                echo "000000 $_z40 0    sub"
 162                echo "160000 1$c 1      sub"
 163                echo "160000 2$c 2      sub"
 164                echo "160000 3$c 3      sub"
 165        ) | git update-index --index-info &&
 166        echo >expect.nosub '\''diff --cc sub
 167index 2ffffff,3ffffff..0000000
 168--- a/sub
 169+++ b/sub
 170@@@ -1,1 -1,1 +1,1 @@@
 171- Subproject commit 2fffffffffffffffffffffffffffffffffffffff
 172 -Subproject commit 3fffffffffffffffffffffffffffffffffffffff
 173++Subproject commit 0000000000000000000000000000000000000000'\'' &&
 174
 175        hh=$(git rev-parse HEAD) &&
 176        sed -e "s/$_z40/$hh/" expect.nosub >expect.withsub
 177
 178'
 179
 180test_expect_success 'combined (empty submodule)' '
 181        rm -fr sub && mkdir sub &&
 182        git diff >actual &&
 183        test_cmp expect.nosub actual
 184'
 185
 186test_expect_success 'combined (with submodule)' '
 187        rm -fr sub &&
 188        git clone --no-checkout . sub &&
 189        git diff >actual &&
 190        test_cmp expect.withsub actual
 191'
 192
 193
 194
 195test_done