t / t6023-merge-file.shon commit Merge branch 'mr/compat-snprintf' (6e79a88)
   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
  57cp new1.txt test.txt
  58test_expect_success "merge without conflict" \
  59        "git merge-file test.txt orig.txt new2.txt"
  60
  61cp new1.txt test2.txt
  62test_expect_success "merge without conflict (missing LF at EOF)" \
  63        "git merge-file test2.txt orig.txt new2.txt"
  64
  65test_expect_success "merge result added missing LF" \
  66        "git diff test.txt test2.txt"
  67
  68cp test.txt backup.txt
  69test_expect_success "merge with conflicts" \
  70        "! git merge-file test.txt orig.txt new3.txt"
  71
  72cat > expect.txt << EOF
  73<<<<<<< test.txt
  74Dominus regit me, et nihil mihi deerit.
  75=======
  76DOMINUS regit me,
  77et nihil mihi deerit.
  78>>>>>>> new3.txt
  79In loco pascuae ibi me collocavit,
  80super aquam refectionis educavit me;
  81animam meam convertit,
  82deduxit me super semitas jusitiae,
  83propter nomen suum.
  84Nam et si ambulavero in medio umbrae mortis,
  85non timebo mala, quoniam tu mecum es:
  86virga tua et baculus tuus ipsa me consolata sunt.
  87EOF
  88
  89test_expect_success "expected conflict markers" "git diff test.txt expect.txt"
  90
  91cp backup.txt test.txt
  92test_expect_success "merge with conflicts, using -L" \
  93        "! git merge-file -L 1 -L 2 test.txt orig.txt new3.txt"
  94
  95cat > expect.txt << EOF
  96<<<<<<< 1
  97Dominus regit me, et nihil mihi deerit.
  98=======
  99DOMINUS regit me,
 100et nihil mihi deerit.
 101>>>>>>> new3.txt
 102In loco pascuae ibi me collocavit,
 103super aquam refectionis educavit me;
 104animam meam convertit,
 105deduxit me super semitas jusitiae,
 106propter nomen suum.
 107Nam et si ambulavero in medio umbrae mortis,
 108non timebo mala, quoniam tu mecum es:
 109virga tua et baculus tuus ipsa me consolata sunt.
 110EOF
 111
 112test_expect_success "expected conflict markers, with -L" \
 113        "git diff test.txt expect.txt"
 114
 115sed "s/ tu / TU /" < new1.txt > new5.txt
 116test_expect_success "conflict in removed tail" \
 117        "! git merge-file -p orig.txt new1.txt new5.txt > out"
 118
 119cat > expect << EOF
 120Dominus regit me,
 121et nihil mihi deerit.
 122In loco pascuae ibi me collocavit,
 123super aquam refectionis educavit me;
 124animam meam convertit,
 125deduxit me super semitas jusitiae,
 126propter nomen suum.
 127<<<<<<< orig.txt
 128=======
 129Nam et si ambulavero in medio umbrae mortis,
 130non timebo mala, quoniam TU mecum es:
 131virga tua et baculus tuus ipsa me consolata sunt.
 132>>>>>>> new5.txt
 133EOF
 134
 135test_expect_success "expected conflict markers" "git diff expect out"
 136
 137test_expect_success 'binary files cannot be merged' '
 138        ! git merge-file -p orig.txt ../test4012.png new1.txt 2> merge.err &&
 139        grep "Cannot merge binary files" merge.err
 140'
 141
 142sed -e "s/deerit.$/deerit;/" -e "s/me;$/me./" < new5.txt > new6.txt
 143sed -e "s/deerit.$/deerit,/" -e "s/me;$/me,/" < new5.txt > new7.txt
 144
 145test_expect_success 'MERGE_ZEALOUS simplifies non-conflicts' '
 146
 147        ! git merge-file -p new6.txt new5.txt new7.txt > output &&
 148        test 1 = $(grep ======= < output | wc -l)
 149
 150'
 151
 152sed -e 's/deerit./&\n\n\n\n/' -e "s/locavit,/locavit;/" < new6.txt > new8.txt
 153sed -e 's/deerit./&\n\n\n\n/' -e "s/locavit,/locavit --/" < new7.txt > new9.txt
 154
 155test_expect_success 'ZEALOUS_ALNUM' '
 156
 157        ! git merge-file -p new8.txt new5.txt new9.txt > merge.out &&
 158        test 1 = $(grep ======= < merge.out | wc -l)
 159
 160'
 161
 162test_done