t / t6023-merge-file.shon commit Merge branch 'mh/show-branch-color' into sb/show-branch-parse-options (1ca2035)
   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        "test_cmp test.txt test2.txt"
  67
  68cp test.txt backup.txt
  69test_expect_success "merge with conflicts" \
  70        "test_must_fail 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" "test_cmp test.txt expect.txt"
  90
  91cp backup.txt test.txt
  92test_expect_success "merge with conflicts, using -L" \
  93        "test_must_fail 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        "test_cmp test.txt expect.txt"
 114
 115sed "s/ tu / TU /" < new1.txt > new5.txt
 116test_expect_success "conflict in removed tail" \
 117        "test_must_fail 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" "test_cmp expect out"
 136
 137test_expect_success 'binary files cannot be merged' '
 138        test_must_fail git merge-file -p \
 139                orig.txt "$TEST_DIRECTORY"/test4012.png new1.txt 2> merge.err &&
 140        grep "Cannot merge binary files" merge.err
 141'
 142
 143sed -e "s/deerit.$/deerit;/" -e "s/me;$/me./" < new5.txt > new6.txt
 144sed -e "s/deerit.$/deerit,/" -e "s/me;$/me,/" < new5.txt > new7.txt
 145
 146test_expect_success 'MERGE_ZEALOUS simplifies non-conflicts' '
 147
 148        test_must_fail git merge-file -p new6.txt new5.txt new7.txt > output &&
 149        test 1 = $(grep ======= < output | wc -l)
 150
 151'
 152
 153sed -e 's/deerit./&%%%%/' -e "s/locavit,/locavit;/"< new6.txt | tr '%' '\012' > new8.txt
 154sed -e 's/deerit./&%%%%/' -e "s/locavit,/locavit --/" < new7.txt | tr '%' '\012' > new9.txt
 155
 156test_expect_success 'ZEALOUS_ALNUM' '
 157
 158        test_must_fail git merge-file -p \
 159                new8.txt new5.txt new9.txt > merge.out &&
 160        test 1 = $(grep ======= < merge.out | wc -l)
 161
 162'
 163
 164cat >expect <<\EOF
 165Dominus regit me,
 166<<<<<<< new8.txt
 167et nihil mihi deerit;
 168
 169
 170
 171
 172In loco pascuae ibi me collocavit;
 173super aquam refectionis educavit me.
 174|||||||
 175et nihil mihi deerit.
 176In loco pascuae ibi me collocavit,
 177super aquam refectionis educavit me;
 178=======
 179et nihil mihi deerit,
 180
 181
 182
 183
 184In loco pascuae ibi me collocavit --
 185super aquam refectionis educavit me,
 186>>>>>>> new9.txt
 187animam meam convertit,
 188deduxit me super semitas jusitiae,
 189propter nomen suum.
 190Nam et si ambulavero in medio umbrae mortis,
 191non timebo mala, quoniam TU mecum es:
 192virga tua et baculus tuus ipsa me consolata sunt.
 193EOF
 194
 195test_expect_success '"diff3 -m" style output (1)' '
 196        test_must_fail git merge-file -p --diff3 \
 197                new8.txt new5.txt new9.txt >actual &&
 198        test_cmp expect actual
 199'
 200
 201test_expect_success '"diff3 -m" style output (2)' '
 202        git config merge.conflictstyle diff3 &&
 203        test_must_fail git merge-file -p \
 204                new8.txt new5.txt new9.txt >actual &&
 205        test_cmp expect actual
 206'
 207
 208test_done