t / t4038-diff-combined.shon commit commit: don't start editor if empty message is given with -m (2520677)
   1#!/bin/sh
   2
   3test_description='combined diff'
   4
   5. ./test-lib.sh
   6. "$TEST_DIRECTORY"/diff-lib.sh
   7
   8setup_helper () {
   9        one=$1 branch=$2 side=$3 &&
  10
  11        git branch $side $branch &&
  12        for l in $one two three fyra
  13        do
  14                echo $l
  15        done >file &&
  16        git add file &&
  17        test_tick &&
  18        git commit -m $branch &&
  19        git checkout $side &&
  20        for l in $one two three quatro
  21        do
  22                echo $l
  23        done >file &&
  24        git add file &&
  25        test_tick &&
  26        git commit -m $side &&
  27        test_must_fail git merge $branch &&
  28        for l in $one three four
  29        do
  30                echo $l
  31        done >file &&
  32        git add file &&
  33        test_tick &&
  34        git commit -m "merge $branch into $side"
  35}
  36
  37verify_helper () {
  38        it=$1 &&
  39
  40        # Ignore lines that were removed only from the other parent
  41        sed -e '
  42                1,/^@@@/d
  43                /^ -/d
  44                s/^\(.\)./\1/
  45        ' "$it" >"$it.actual.1" &&
  46        sed -e '
  47                1,/^@@@/d
  48                /^- /d
  49                s/^.\(.\)/\1/
  50        ' "$it" >"$it.actual.2" &&
  51
  52        git diff "$it^" "$it" -- | sed -e '1,/^@@/d' >"$it.expect.1" &&
  53        test_cmp "$it.expect.1" "$it.actual.1" &&
  54
  55        git diff "$it^2" "$it" -- | sed -e '1,/^@@/d' >"$it.expect.2" &&
  56        test_cmp "$it.expect.2" "$it.actual.2"
  57}
  58
  59test_expect_success setup '
  60        >file &&
  61        git add file &&
  62        test_tick &&
  63        git commit -m initial &&
  64
  65        git branch withone &&
  66        git branch sansone &&
  67
  68        git checkout withone &&
  69        setup_helper one withone sidewithone &&
  70
  71        git checkout sansone &&
  72        setup_helper "" sansone sidesansone
  73'
  74
  75test_expect_success 'check combined output (1)' '
  76        git show sidewithone -- >sidewithone &&
  77        verify_helper sidewithone
  78'
  79
  80test_expect_success 'check combined output (2)' '
  81        git show sidesansone -- >sidesansone &&
  82        verify_helper sidesansone
  83'
  84
  85test_expect_success 'diagnose truncated file' '
  86        >file &&
  87        git add file &&
  88        git commit --amend -C HEAD &&
  89        git show >out &&
  90        grep "diff --cc file" out
  91'
  92
  93test_expect_success 'setup for --cc --raw' '
  94        blob=$(echo file | git hash-object --stdin -w) &&
  95        base_tree=$(echo "100644 blob $blob     file" | git mktree) &&
  96        trees= &&
  97        for i in `test_seq 1 40`
  98        do
  99                blob=$(echo file$i | git hash-object --stdin -w) &&
 100                trees="$trees$(echo "100644 blob $blob  file" | git mktree)$LF"
 101        done
 102'
 103
 104test_expect_success 'check --cc --raw with four trees' '
 105        four_trees=$(echo "$trees" | sed -e 4q) &&
 106        git diff --cc --raw $four_trees $base_tree >out &&
 107        # Check for four leading colons in the output:
 108        grep "^::::[^:]" out
 109'
 110
 111test_expect_success 'check --cc --raw with forty trees' '
 112        git diff --cc --raw $trees $base_tree >out &&
 113        # Check for forty leading colons in the output:
 114        grep "^::::::::::::::::::::::::::::::::::::::::[^:]" out
 115'
 116
 117test_expect_success 'setup combined ignore spaces' '
 118        git checkout master &&
 119        >test &&
 120        git add test &&
 121        git commit -m initial &&
 122
 123        tr -d Q <<-\EOF >test &&
 124        always coalesce
 125        eol space coalesce Q
 126        space  change coalesce
 127        all spa ces coalesce
 128        eol spaces Q
 129        space  change
 130        all spa ces
 131        EOF
 132        git commit -m "test space change" -a &&
 133
 134        git checkout -b side HEAD^ &&
 135        tr -d Q <<-\EOF >test &&
 136        always coalesce
 137        eol space coalesce
 138        space change coalesce
 139        all spaces coalesce
 140        eol spaces
 141        space change
 142        all spaces
 143        EOF
 144        git commit -m "test other space changes" -a &&
 145
 146        test_must_fail git merge master &&
 147        tr -d Q <<-\EOF >test &&
 148        eol spaces Q
 149        space  change
 150        all spa ces
 151        EOF
 152        git commit -m merged -a
 153'
 154
 155test_expect_success 'check combined output (no ignore space)' '
 156        git show >actual.tmp &&
 157        sed -e "1,/^@@@/d" < actual.tmp >actual &&
 158        tr -d Q <<-\EOF >expected &&
 159        --always coalesce
 160        - eol space coalesce
 161        - space change coalesce
 162        - all spaces coalesce
 163        - eol spaces
 164        - space change
 165        - all spaces
 166         -eol space coalesce Q
 167         -space  change coalesce
 168         -all spa ces coalesce
 169        + eol spaces Q
 170        + space  change
 171        + all spa ces
 172        EOF
 173        compare_diff_patch expected actual
 174'
 175
 176test_expect_success 'check combined output (ignore space at eol)' '
 177        git show --ignore-space-at-eol >actual.tmp &&
 178        sed -e "1,/^@@@/d" < actual.tmp >actual &&
 179        tr -d Q <<-\EOF >expected &&
 180        --always coalesce
 181        --eol space coalesce
 182        - space change coalesce
 183        - all spaces coalesce
 184         -space  change coalesce
 185         -all spa ces coalesce
 186          eol spaces Q
 187        - space change
 188        - all spaces
 189        + space  change
 190        + all spa ces
 191        EOF
 192        compare_diff_patch expected actual
 193'
 194
 195test_expect_success 'check combined output (ignore space change)' '
 196        git show -b >actual.tmp &&
 197        sed -e "1,/^@@@/d" < actual.tmp >actual &&
 198        tr -d Q <<-\EOF >expected &&
 199        --always coalesce
 200        --eol space coalesce
 201        --space change coalesce
 202        - all spaces coalesce
 203         -all spa ces coalesce
 204          eol spaces Q
 205          space  change
 206        - all spaces
 207        + all spa ces
 208        EOF
 209        compare_diff_patch expected actual
 210'
 211
 212test_expect_success 'check combined output (ignore all spaces)' '
 213        git show -w >actual.tmp &&
 214        sed -e "1,/^@@@/d" < actual.tmp >actual &&
 215        tr -d Q <<-\EOF >expected &&
 216        --always coalesce
 217        --eol space coalesce
 218        --space change coalesce
 219        --all spaces coalesce
 220          eol spaces Q
 221          space  change
 222          all spa ces
 223        EOF
 224        compare_diff_patch expected actual
 225'
 226
 227test_done