t / t6023-merge-file.shon commit t/t5150: remove space from sed script (6f89384)
   1#!/bin/sh
   2
   3test_description='RCS merge replacement: merge-file'
   4. ./test-lib.sh
   5
   6cat > orig.txt << EOF
   7Dominus regit me,
   8et nihil mihi deerit.
   9In loco pascuae ibi me collocavit,
  10super aquam refectionis educavit me;
  11animam meam convertit,
  12deduxit me super semitas jusitiae,
  13propter nomen suum.
  14EOF
  15
  16cat > new1.txt << EOF
  17Dominus regit me,
  18et nihil mihi deerit.
  19In loco pascuae ibi me collocavit,
  20super aquam refectionis educavit me;
  21animam meam convertit,
  22deduxit me super semitas jusitiae,
  23propter nomen suum.
  24Nam et si ambulavero in medio umbrae mortis,
  25non timebo mala, quoniam tu mecum es:
  26virga tua et baculus tuus ipsa me consolata sunt.
  27EOF
  28
  29cat > new2.txt << EOF
  30Dominus regit me, et nihil mihi deerit.
  31In loco pascuae ibi me collocavit,
  32super aquam refectionis educavit me;
  33animam meam convertit,
  34deduxit me super semitas jusitiae,
  35propter nomen suum.
  36EOF
  37
  38cat > new3.txt << EOF
  39DOMINUS regit me,
  40et nihil mihi deerit.
  41In loco pascuae ibi me collocavit,
  42super aquam refectionis educavit me;
  43animam meam convertit,
  44deduxit me super semitas jusitiae,
  45propter nomen suum.
  46EOF
  47
  48cat > new4.txt << EOF
  49Dominus regit me, et nihil mihi deerit.
  50In loco pascuae ibi me collocavit,
  51super aquam refectionis educavit me;
  52animam meam convertit,
  53deduxit me super semitas jusitiae,
  54EOF
  55printf "propter nomen suum." >> new4.txt
  56
  57test_expect_success 'merge with no changes' '
  58        cp orig.txt test.txt &&
  59        git merge-file test.txt orig.txt orig.txt &&
  60        test_cmp test.txt orig.txt
  61'
  62
  63cp new1.txt test.txt
  64test_expect_success "merge without conflict" \
  65        "git merge-file test.txt orig.txt new2.txt"
  66
  67cp new1.txt test.txt
  68test_expect_success "merge without conflict (--quiet)" \
  69        "git merge-file --quiet test.txt orig.txt new2.txt"
  70
  71cp new1.txt test2.txt
  72test_expect_success "merge without conflict (missing LF at EOF)" \
  73        "git merge-file test2.txt orig.txt new2.txt"
  74
  75test_expect_success "merge result added missing LF" \
  76        "test_cmp test.txt test2.txt"
  77
  78cp test.txt backup.txt
  79test_expect_success "merge with conflicts" \
  80        "test_must_fail git merge-file test.txt orig.txt new3.txt"
  81
  82cat > expect.txt << EOF
  83<<<<<<< test.txt
  84Dominus regit me, et nihil mihi deerit.
  85=======
  86DOMINUS regit me,
  87et nihil mihi deerit.
  88>>>>>>> new3.txt
  89In loco pascuae ibi me collocavit,
  90super aquam refectionis educavit me;
  91animam meam convertit,
  92deduxit me super semitas jusitiae,
  93propter nomen suum.
  94Nam et si ambulavero in medio umbrae mortis,
  95non timebo mala, quoniam tu mecum es:
  96virga tua et baculus tuus ipsa me consolata sunt.
  97EOF
  98
  99test_expect_success "expected conflict markers" "test_cmp test.txt expect.txt"
 100
 101cp backup.txt test.txt
 102test_expect_success "merge with conflicts, using -L" \
 103        "test_must_fail git merge-file -L 1 -L 2 test.txt orig.txt new3.txt"
 104
 105cat > expect.txt << EOF
 106<<<<<<< 1
 107Dominus regit me, et nihil mihi deerit.
 108=======
 109DOMINUS regit me,
 110et nihil mihi deerit.
 111>>>>>>> new3.txt
 112In loco pascuae ibi me collocavit,
 113super aquam refectionis educavit me;
 114animam meam convertit,
 115deduxit me super semitas jusitiae,
 116propter nomen suum.
 117Nam et si ambulavero in medio umbrae mortis,
 118non timebo mala, quoniam tu mecum es:
 119virga tua et baculus tuus ipsa me consolata sunt.
 120EOF
 121
 122test_expect_success "expected conflict markers, with -L" \
 123        "test_cmp test.txt expect.txt"
 124
 125sed "s/ tu / TU /" < new1.txt > new5.txt
 126test_expect_success "conflict in removed tail" \
 127        "test_must_fail git merge-file -p orig.txt new1.txt new5.txt > out"
 128
 129cat > expect << EOF
 130Dominus regit me,
 131et nihil mihi deerit.
 132In loco pascuae ibi me collocavit,
 133super aquam refectionis educavit me;
 134animam meam convertit,
 135deduxit me super semitas jusitiae,
 136propter nomen suum.
 137<<<<<<< orig.txt
 138=======
 139Nam et si ambulavero in medio umbrae mortis,
 140non timebo mala, quoniam TU mecum es:
 141virga tua et baculus tuus ipsa me consolata sunt.
 142>>>>>>> new5.txt
 143EOF
 144
 145test_expect_success "expected conflict markers" "test_cmp expect out"
 146
 147test_expect_success 'binary files cannot be merged' '
 148        test_must_fail git merge-file -p \
 149                orig.txt "$TEST_DIRECTORY"/test4012.png new1.txt 2> merge.err &&
 150        grep "Cannot merge binary files" merge.err
 151'
 152
 153sed -e "s/deerit.\$/deerit;/" -e "s/me;\$/me./" < new5.txt > new6.txt
 154sed -e "s/deerit.\$/deerit,/" -e "s/me;\$/me,/" < new5.txt > new7.txt
 155
 156test_expect_success 'MERGE_ZEALOUS simplifies non-conflicts' '
 157
 158        test_must_fail git merge-file -p new6.txt new5.txt new7.txt > output &&
 159        test 1 = $(grep ======= < output | wc -l)
 160
 161'
 162
 163sed -e 's/deerit./&%%%%/' -e "s/locavit,/locavit;/"< new6.txt | tr '%' '\012' > new8.txt
 164sed -e 's/deerit./&%%%%/' -e "s/locavit,/locavit --/" < new7.txt | tr '%' '\012' > new9.txt
 165
 166test_expect_success 'ZEALOUS_ALNUM' '
 167
 168        test_must_fail git merge-file -p \
 169                new8.txt new5.txt new9.txt > merge.out &&
 170        test 1 = $(grep ======= < merge.out | wc -l)
 171
 172'
 173
 174cat >expect <<\EOF
 175Dominus regit me,
 176<<<<<<< new8.txt
 177et nihil mihi deerit;
 178
 179
 180
 181
 182In loco pascuae ibi me collocavit;
 183super aquam refectionis educavit me.
 184||||||| new5.txt
 185et nihil mihi deerit.
 186In loco pascuae ibi me collocavit,
 187super aquam refectionis educavit me;
 188=======
 189et nihil mihi deerit,
 190
 191
 192
 193
 194In loco pascuae ibi me collocavit --
 195super aquam refectionis educavit me,
 196>>>>>>> new9.txt
 197animam meam convertit,
 198deduxit me super semitas jusitiae,
 199propter nomen suum.
 200Nam et si ambulavero in medio umbrae mortis,
 201non timebo mala, quoniam TU mecum es:
 202virga tua et baculus tuus ipsa me consolata sunt.
 203EOF
 204
 205test_expect_success '"diff3 -m" style output (1)' '
 206        test_must_fail git merge-file -p --diff3 \
 207                new8.txt new5.txt new9.txt >actual &&
 208        test_cmp expect actual
 209'
 210
 211test_expect_success '"diff3 -m" style output (2)' '
 212        git config merge.conflictstyle diff3 &&
 213        test_must_fail git merge-file -p \
 214                new8.txt new5.txt new9.txt >actual &&
 215        test_cmp expect actual
 216'
 217
 218cat >expect <<\EOF
 219Dominus regit me,
 220<<<<<<<<<< new8.txt
 221et nihil mihi deerit;
 222
 223
 224
 225
 226In loco pascuae ibi me collocavit;
 227super aquam refectionis educavit me.
 228|||||||||| new5.txt
 229et nihil mihi deerit.
 230In loco pascuae ibi me collocavit,
 231super aquam refectionis educavit me;
 232==========
 233et nihil mihi deerit,
 234
 235
 236
 237
 238In loco pascuae ibi me collocavit --
 239super aquam refectionis educavit me,
 240>>>>>>>>>> new9.txt
 241animam meam convertit,
 242deduxit me super semitas jusitiae,
 243propter nomen suum.
 244Nam et si ambulavero in medio umbrae mortis,
 245non timebo mala, quoniam TU mecum es:
 246virga tua et baculus tuus ipsa me consolata sunt.
 247EOF
 248
 249test_expect_success 'marker size' '
 250        test_must_fail git merge-file -p --marker-size=10 \
 251                new8.txt new5.txt new9.txt >actual &&
 252        test_cmp expect actual
 253'
 254
 255test_done