t / t6023-merge-file.shon commit git_config_maybe_bool() (8420ccd)
   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 test2.txt
  68test_expect_success "merge without conflict (missing LF at EOF)" \
  69        "git merge-file test2.txt orig.txt new2.txt"
  70
  71test_expect_success "merge result added missing LF" \
  72        "test_cmp test.txt test2.txt"
  73
  74cp test.txt backup.txt
  75test_expect_success "merge with conflicts" \
  76        "test_must_fail git merge-file test.txt orig.txt new3.txt"
  77
  78cat > expect.txt << EOF
  79<<<<<<< test.txt
  80Dominus regit me, et nihil mihi deerit.
  81=======
  82DOMINUS regit me,
  83et nihil mihi deerit.
  84>>>>>>> new3.txt
  85In loco pascuae ibi me collocavit,
  86super aquam refectionis educavit me;
  87animam meam convertit,
  88deduxit me super semitas jusitiae,
  89propter nomen suum.
  90Nam et si ambulavero in medio umbrae mortis,
  91non timebo mala, quoniam tu mecum es:
  92virga tua et baculus tuus ipsa me consolata sunt.
  93EOF
  94
  95test_expect_success "expected conflict markers" "test_cmp test.txt expect.txt"
  96
  97cp backup.txt test.txt
  98test_expect_success "merge with conflicts, using -L" \
  99        "test_must_fail git merge-file -L 1 -L 2 test.txt orig.txt new3.txt"
 100
 101cat > expect.txt << EOF
 102<<<<<<< 1
 103Dominus regit me, et nihil mihi deerit.
 104=======
 105DOMINUS regit me,
 106et nihil mihi deerit.
 107>>>>>>> new3.txt
 108In loco pascuae ibi me collocavit,
 109super aquam refectionis educavit me;
 110animam meam convertit,
 111deduxit me super semitas jusitiae,
 112propter nomen suum.
 113Nam et si ambulavero in medio umbrae mortis,
 114non timebo mala, quoniam tu mecum es:
 115virga tua et baculus tuus ipsa me consolata sunt.
 116EOF
 117
 118test_expect_success "expected conflict markers, with -L" \
 119        "test_cmp test.txt expect.txt"
 120
 121sed "s/ tu / TU /" < new1.txt > new5.txt
 122test_expect_success "conflict in removed tail" \
 123        "test_must_fail git merge-file -p orig.txt new1.txt new5.txt > out"
 124
 125cat > expect << EOF
 126Dominus regit me,
 127et nihil mihi deerit.
 128In loco pascuae ibi me collocavit,
 129super aquam refectionis educavit me;
 130animam meam convertit,
 131deduxit me super semitas jusitiae,
 132propter nomen suum.
 133<<<<<<< orig.txt
 134=======
 135Nam et si ambulavero in medio umbrae mortis,
 136non timebo mala, quoniam TU mecum es:
 137virga tua et baculus tuus ipsa me consolata sunt.
 138>>>>>>> new5.txt
 139EOF
 140
 141test_expect_success "expected conflict markers" "test_cmp expect out"
 142
 143test_expect_success 'binary files cannot be merged' '
 144        test_must_fail git merge-file -p \
 145                orig.txt "$TEST_DIRECTORY"/test4012.png new1.txt 2> merge.err &&
 146        grep "Cannot merge binary files" merge.err
 147'
 148
 149sed -e "s/deerit.\$/deerit;/" -e "s/me;\$/me./" < new5.txt > new6.txt
 150sed -e "s/deerit.\$/deerit,/" -e "s/me;\$/me,/" < new5.txt > new7.txt
 151
 152test_expect_success 'MERGE_ZEALOUS simplifies non-conflicts' '
 153
 154        test_must_fail git merge-file -p new6.txt new5.txt new7.txt > output &&
 155        test 1 = $(grep ======= < output | wc -l)
 156
 157'
 158
 159sed -e 's/deerit./&%%%%/' -e "s/locavit,/locavit;/"< new6.txt | tr '%' '\012' > new8.txt
 160sed -e 's/deerit./&%%%%/' -e "s/locavit,/locavit --/" < new7.txt | tr '%' '\012' > new9.txt
 161
 162test_expect_success 'ZEALOUS_ALNUM' '
 163
 164        test_must_fail git merge-file -p \
 165                new8.txt new5.txt new9.txt > merge.out &&
 166        test 1 = $(grep ======= < merge.out | wc -l)
 167
 168'
 169
 170cat >expect <<\EOF
 171Dominus regit me,
 172<<<<<<< new8.txt
 173et nihil mihi deerit;
 174
 175
 176
 177
 178In loco pascuae ibi me collocavit;
 179super aquam refectionis educavit me.
 180|||||||
 181et nihil mihi deerit.
 182In loco pascuae ibi me collocavit,
 183super aquam refectionis educavit me;
 184=======
 185et nihil mihi deerit,
 186
 187
 188
 189
 190In loco pascuae ibi me collocavit --
 191super aquam refectionis educavit me,
 192>>>>>>> new9.txt
 193animam meam convertit,
 194deduxit me super semitas jusitiae,
 195propter nomen suum.
 196Nam et si ambulavero in medio umbrae mortis,
 197non timebo mala, quoniam TU mecum es:
 198virga tua et baculus tuus ipsa me consolata sunt.
 199EOF
 200
 201test_expect_success '"diff3 -m" style output (1)' '
 202        test_must_fail git merge-file -p --diff3 \
 203                new8.txt new5.txt new9.txt >actual &&
 204        test_cmp expect actual
 205'
 206
 207test_expect_success '"diff3 -m" style output (2)' '
 208        git config merge.conflictstyle diff3 &&
 209        test_must_fail git merge-file -p \
 210                new8.txt new5.txt new9.txt >actual &&
 211        test_cmp expect actual
 212'
 213
 214test_done