t / t6023-merge-file.shon commit Merge branch 'sb/perf-without-installed-git' into maint (2c3cb52)
   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
  67test_expect_success 'works in subdirectory' '
  68        mkdir dir &&
  69        cp new1.txt dir/a.txt &&
  70        cp orig.txt dir/o.txt &&
  71        cp new2.txt dir/b.txt &&
  72        ( cd dir && git merge-file a.txt o.txt b.txt ) &&
  73        test_path_is_missing a.txt
  74'
  75
  76cp new1.txt test.txt
  77test_expect_success "merge without conflict (--quiet)" \
  78        "git merge-file --quiet test.txt orig.txt new2.txt"
  79
  80cp new1.txt test2.txt
  81test_expect_failure "merge without conflict (missing LF at EOF)" \
  82        "git merge-file test2.txt orig.txt new4.txt"
  83
  84test_expect_failure "merge result added missing LF" \
  85        "test_cmp test.txt test2.txt"
  86
  87cp new4.txt test3.txt
  88test_expect_success "merge without conflict (missing LF at EOF, away from change in the other file)" \
  89        "git merge-file --quiet test3.txt new2.txt new3.txt"
  90
  91cat > expect.txt << EOF
  92DOMINUS regit me,
  93et nihil mihi deerit.
  94In loco pascuae ibi me collocavit,
  95super aquam refectionis educavit me;
  96animam meam convertit,
  97deduxit me super semitas jusitiae,
  98EOF
  99printf "propter nomen suum." >> expect.txt
 100
 101test_expect_success "merge does not add LF away of change" \
 102        "test_cmp test3.txt expect.txt"
 103
 104cp test.txt backup.txt
 105test_expect_success "merge with conflicts" \
 106        "test_must_fail git merge-file test.txt orig.txt new3.txt"
 107
 108cat > expect.txt << EOF
 109<<<<<<< test.txt
 110Dominus regit me, et nihil mihi deerit.
 111=======
 112DOMINUS regit me,
 113et nihil mihi deerit.
 114>>>>>>> new3.txt
 115In loco pascuae ibi me collocavit,
 116super aquam refectionis educavit me;
 117animam meam convertit,
 118deduxit me super semitas jusitiae,
 119propter nomen suum.
 120Nam et si ambulavero in medio umbrae mortis,
 121non timebo mala, quoniam tu mecum es:
 122virga tua et baculus tuus ipsa me consolata sunt.
 123EOF
 124
 125test_expect_success "expected conflict markers" "test_cmp test.txt expect.txt"
 126
 127cp backup.txt test.txt
 128
 129cat > expect.txt << EOF
 130Dominus regit me, et nihil mihi deerit.
 131In loco pascuae ibi me collocavit,
 132super aquam refectionis educavit me;
 133animam meam convertit,
 134deduxit me super semitas jusitiae,
 135propter nomen suum.
 136Nam et si ambulavero in medio umbrae mortis,
 137non timebo mala, quoniam tu mecum es:
 138virga tua et baculus tuus ipsa me consolata sunt.
 139EOF
 140test_expect_success "merge conflicting with --ours" \
 141        "git merge-file --ours test.txt orig.txt new3.txt && test_cmp test.txt expect.txt"
 142cp backup.txt test.txt
 143
 144cat > expect.txt << EOF
 145DOMINUS regit me,
 146et nihil mihi deerit.
 147In loco pascuae ibi me collocavit,
 148super aquam refectionis educavit me;
 149animam meam convertit,
 150deduxit me super semitas jusitiae,
 151propter nomen suum.
 152Nam et si ambulavero in medio umbrae mortis,
 153non timebo mala, quoniam tu mecum es:
 154virga tua et baculus tuus ipsa me consolata sunt.
 155EOF
 156test_expect_success "merge conflicting with --theirs" \
 157        "git merge-file --theirs test.txt orig.txt new3.txt && test_cmp test.txt expect.txt"
 158cp backup.txt test.txt
 159
 160cat > expect.txt << EOF
 161Dominus regit me, et nihil mihi deerit.
 162DOMINUS regit me,
 163et nihil mihi deerit.
 164In loco pascuae ibi me collocavit,
 165super aquam refectionis educavit me;
 166animam meam convertit,
 167deduxit me super semitas jusitiae,
 168propter nomen suum.
 169Nam et si ambulavero in medio umbrae mortis,
 170non timebo mala, quoniam tu mecum es:
 171virga tua et baculus tuus ipsa me consolata sunt.
 172EOF
 173test_expect_success "merge conflicting with --union" \
 174        "git merge-file --union test.txt orig.txt new3.txt && test_cmp test.txt expect.txt"
 175cp backup.txt test.txt
 176
 177test_expect_success "merge with conflicts, using -L" \
 178        "test_must_fail git merge-file -L 1 -L 2 test.txt orig.txt new3.txt"
 179
 180cat > expect.txt << EOF
 181<<<<<<< 1
 182Dominus regit me, et nihil mihi deerit.
 183=======
 184DOMINUS regit me,
 185et nihil mihi deerit.
 186>>>>>>> new3.txt
 187In loco pascuae ibi me collocavit,
 188super aquam refectionis educavit me;
 189animam meam convertit,
 190deduxit me super semitas jusitiae,
 191propter nomen suum.
 192Nam et si ambulavero in medio umbrae mortis,
 193non timebo mala, quoniam tu mecum es:
 194virga tua et baculus tuus ipsa me consolata sunt.
 195EOF
 196
 197test_expect_success "expected conflict markers, with -L" \
 198        "test_cmp test.txt expect.txt"
 199
 200sed "s/ tu / TU /" < new1.txt > new5.txt
 201test_expect_success "conflict in removed tail" \
 202        "test_must_fail git merge-file -p orig.txt new1.txt new5.txt > out"
 203
 204cat > expect << EOF
 205Dominus regit me,
 206et nihil mihi deerit.
 207In loco pascuae ibi me collocavit,
 208super aquam refectionis educavit me;
 209animam meam convertit,
 210deduxit me super semitas jusitiae,
 211propter nomen suum.
 212<<<<<<< orig.txt
 213=======
 214Nam et si ambulavero in medio umbrae mortis,
 215non timebo mala, quoniam TU mecum es:
 216virga tua et baculus tuus ipsa me consolata sunt.
 217>>>>>>> new5.txt
 218EOF
 219
 220test_expect_success "expected conflict markers" "test_cmp expect out"
 221
 222test_expect_success 'binary files cannot be merged' '
 223        test_must_fail git merge-file -p \
 224                orig.txt "$TEST_DIRECTORY"/test-binary-1.png new1.txt 2> merge.err &&
 225        grep "Cannot merge binary files" merge.err
 226'
 227
 228sed -e "s/deerit.\$/deerit;/" -e "s/me;\$/me./" < new5.txt > new6.txt
 229sed -e "s/deerit.\$/deerit,/" -e "s/me;\$/me,/" < new5.txt > new7.txt
 230
 231test_expect_success 'MERGE_ZEALOUS simplifies non-conflicts' '
 232
 233        test_must_fail git merge-file -p new6.txt new5.txt new7.txt > output &&
 234        test 1 = $(grep ======= < output | wc -l)
 235
 236'
 237
 238sed -e 's/deerit./&%%%%/' -e "s/locavit,/locavit;/"< new6.txt | tr '%' '\012' > new8.txt
 239sed -e 's/deerit./&%%%%/' -e "s/locavit,/locavit --/" < new7.txt | tr '%' '\012' > new9.txt
 240
 241test_expect_success 'ZEALOUS_ALNUM' '
 242
 243        test_must_fail git merge-file -p \
 244                new8.txt new5.txt new9.txt > merge.out &&
 245        test 1 = $(grep ======= < merge.out | wc -l)
 246
 247'
 248
 249cat >expect <<\EOF
 250Dominus regit me,
 251<<<<<<< new8.txt
 252et nihil mihi deerit;
 253
 254
 255
 256
 257In loco pascuae ibi me collocavit;
 258super aquam refectionis educavit me.
 259||||||| new5.txt
 260et nihil mihi deerit.
 261In loco pascuae ibi me collocavit,
 262super aquam refectionis educavit me;
 263=======
 264et nihil mihi deerit,
 265
 266
 267
 268
 269In loco pascuae ibi me collocavit --
 270super aquam refectionis educavit me,
 271>>>>>>> new9.txt
 272animam meam convertit,
 273deduxit me super semitas jusitiae,
 274propter nomen suum.
 275Nam et si ambulavero in medio umbrae mortis,
 276non timebo mala, quoniam TU mecum es:
 277virga tua et baculus tuus ipsa me consolata sunt.
 278EOF
 279
 280test_expect_success '"diff3 -m" style output (1)' '
 281        test_must_fail git merge-file -p --diff3 \
 282                new8.txt new5.txt new9.txt >actual &&
 283        test_cmp expect actual
 284'
 285
 286test_expect_success '"diff3 -m" style output (2)' '
 287        git config merge.conflictstyle diff3 &&
 288        test_must_fail git merge-file -p \
 289                new8.txt new5.txt new9.txt >actual &&
 290        test_cmp expect actual
 291'
 292
 293cat >expect <<\EOF
 294Dominus regit me,
 295<<<<<<<<<< new8.txt
 296et nihil mihi deerit;
 297
 298
 299
 300
 301In loco pascuae ibi me collocavit;
 302super aquam refectionis educavit me.
 303|||||||||| new5.txt
 304et nihil mihi deerit.
 305In loco pascuae ibi me collocavit,
 306super aquam refectionis educavit me;
 307==========
 308et nihil mihi deerit,
 309
 310
 311
 312
 313In loco pascuae ibi me collocavit --
 314super aquam refectionis educavit me,
 315>>>>>>>>>> new9.txt
 316animam meam convertit,
 317deduxit me super semitas jusitiae,
 318propter nomen suum.
 319Nam et si ambulavero in medio umbrae mortis,
 320non timebo mala, quoniam TU mecum es:
 321virga tua et baculus tuus ipsa me consolata sunt.
 322EOF
 323
 324test_expect_success 'marker size' '
 325        test_must_fail git merge-file -p --marker-size=10 \
 326                new8.txt new5.txt new9.txt >actual &&
 327        test_cmp expect actual
 328'
 329
 330printf "line1\nline2\nline3" >nolf-orig.txt
 331printf "line1\nline2\nline3x" >nolf-diff1.txt
 332printf "line1\nline2\nline3y" >nolf-diff2.txt
 333
 334test_expect_success 'conflict at EOF without LF resolved by --ours' \
 335        'git merge-file -p --ours nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt &&
 336         printf "line1\nline2\nline3x" >expect.txt &&
 337         test_cmp expect.txt output.txt'
 338
 339test_expect_success 'conflict at EOF without LF resolved by --theirs' \
 340        'git merge-file -p --theirs nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt &&
 341         printf "line1\nline2\nline3y" >expect.txt &&
 342         test_cmp expect.txt output.txt'
 343
 344test_expect_success 'conflict at EOF without LF resolved by --union' \
 345        'git merge-file -p --union nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt &&
 346         printf "line1\nline2\nline3x\nline3y" >expect.txt &&
 347         test_cmp expect.txt output.txt'
 348
 349test_done