t / t6023-merge-file.shon commit blame $path: avoid getting fooled by case insensitive filesystems (ffcabcc)
   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'
  74
  75cp new1.txt test.txt
  76test_expect_success "merge without conflict (--quiet)" \
  77        "git merge-file --quiet test.txt orig.txt new2.txt"
  78
  79cp new1.txt test2.txt
  80test_expect_success "merge without conflict (missing LF at EOF)" \
  81        "git merge-file test2.txt orig.txt new2.txt"
  82
  83test_expect_success "merge result added missing LF" \
  84        "test_cmp test.txt test2.txt"
  85
  86cp test.txt backup.txt
  87test_expect_success "merge with conflicts" \
  88        "test_must_fail git merge-file test.txt orig.txt new3.txt"
  89
  90cat > expect.txt << EOF
  91<<<<<<< test.txt
  92Dominus regit me, et nihil mihi deerit.
  93=======
  94DOMINUS regit me,
  95et nihil mihi deerit.
  96>>>>>>> new3.txt
  97In loco pascuae ibi me collocavit,
  98super aquam refectionis educavit me;
  99animam meam convertit,
 100deduxit me super semitas jusitiae,
 101propter nomen suum.
 102Nam et si ambulavero in medio umbrae mortis,
 103non timebo mala, quoniam tu mecum es:
 104virga tua et baculus tuus ipsa me consolata sunt.
 105EOF
 106
 107test_expect_success "expected conflict markers" "test_cmp test.txt expect.txt"
 108
 109cp backup.txt test.txt
 110test_expect_success "merge with conflicts, using -L" \
 111        "test_must_fail git merge-file -L 1 -L 2 test.txt orig.txt new3.txt"
 112
 113cat > expect.txt << EOF
 114<<<<<<< 1
 115Dominus regit me, et nihil mihi deerit.
 116=======
 117DOMINUS regit me,
 118et nihil mihi deerit.
 119>>>>>>> new3.txt
 120In loco pascuae ibi me collocavit,
 121super aquam refectionis educavit me;
 122animam meam convertit,
 123deduxit me super semitas jusitiae,
 124propter nomen suum.
 125Nam et si ambulavero in medio umbrae mortis,
 126non timebo mala, quoniam tu mecum es:
 127virga tua et baculus tuus ipsa me consolata sunt.
 128EOF
 129
 130test_expect_success "expected conflict markers, with -L" \
 131        "test_cmp test.txt expect.txt"
 132
 133sed "s/ tu / TU /" < new1.txt > new5.txt
 134test_expect_success "conflict in removed tail" \
 135        "test_must_fail git merge-file -p orig.txt new1.txt new5.txt > out"
 136
 137cat > expect << EOF
 138Dominus regit me,
 139et nihil mihi deerit.
 140In loco pascuae ibi me collocavit,
 141super aquam refectionis educavit me;
 142animam meam convertit,
 143deduxit me super semitas jusitiae,
 144propter nomen suum.
 145<<<<<<< orig.txt
 146=======
 147Nam et si ambulavero in medio umbrae mortis,
 148non timebo mala, quoniam TU mecum es:
 149virga tua et baculus tuus ipsa me consolata sunt.
 150>>>>>>> new5.txt
 151EOF
 152
 153test_expect_success "expected conflict markers" "test_cmp expect out"
 154
 155test_expect_success 'binary files cannot be merged' '
 156        test_must_fail git merge-file -p \
 157                orig.txt "$TEST_DIRECTORY"/test-binary-1.png new1.txt 2> merge.err &&
 158        grep "Cannot merge binary files" merge.err
 159'
 160
 161sed -e "s/deerit.\$/deerit;/" -e "s/me;\$/me./" < new5.txt > new6.txt
 162sed -e "s/deerit.\$/deerit,/" -e "s/me;\$/me,/" < new5.txt > new7.txt
 163
 164test_expect_success 'MERGE_ZEALOUS simplifies non-conflicts' '
 165
 166        test_must_fail git merge-file -p new6.txt new5.txt new7.txt > output &&
 167        test 1 = $(grep ======= < output | wc -l)
 168
 169'
 170
 171sed -e 's/deerit./&%%%%/' -e "s/locavit,/locavit;/"< new6.txt | tr '%' '\012' > new8.txt
 172sed -e 's/deerit./&%%%%/' -e "s/locavit,/locavit --/" < new7.txt | tr '%' '\012' > new9.txt
 173
 174test_expect_success 'ZEALOUS_ALNUM' '
 175
 176        test_must_fail git merge-file -p \
 177                new8.txt new5.txt new9.txt > merge.out &&
 178        test 1 = $(grep ======= < merge.out | wc -l)
 179
 180'
 181
 182cat >expect <<\EOF
 183Dominus regit me,
 184<<<<<<< new8.txt
 185et nihil mihi deerit;
 186
 187
 188
 189
 190In loco pascuae ibi me collocavit;
 191super aquam refectionis educavit me.
 192||||||| new5.txt
 193et nihil mihi deerit.
 194In loco pascuae ibi me collocavit,
 195super aquam refectionis educavit me;
 196=======
 197et nihil mihi deerit,
 198
 199
 200
 201
 202In loco pascuae ibi me collocavit --
 203super aquam refectionis educavit me,
 204>>>>>>> new9.txt
 205animam meam convertit,
 206deduxit me super semitas jusitiae,
 207propter nomen suum.
 208Nam et si ambulavero in medio umbrae mortis,
 209non timebo mala, quoniam TU mecum es:
 210virga tua et baculus tuus ipsa me consolata sunt.
 211EOF
 212
 213test_expect_success '"diff3 -m" style output (1)' '
 214        test_must_fail git merge-file -p --diff3 \
 215                new8.txt new5.txt new9.txt >actual &&
 216        test_cmp expect actual
 217'
 218
 219test_expect_success '"diff3 -m" style output (2)' '
 220        git config merge.conflictstyle diff3 &&
 221        test_must_fail git merge-file -p \
 222                new8.txt new5.txt new9.txt >actual &&
 223        test_cmp expect actual
 224'
 225
 226cat >expect <<\EOF
 227Dominus regit me,
 228<<<<<<<<<< new8.txt
 229et nihil mihi deerit;
 230
 231
 232
 233
 234In loco pascuae ibi me collocavit;
 235super aquam refectionis educavit me.
 236|||||||||| new5.txt
 237et nihil mihi deerit.
 238In loco pascuae ibi me collocavit,
 239super aquam refectionis educavit me;
 240==========
 241et nihil mihi deerit,
 242
 243
 244
 245
 246In loco pascuae ibi me collocavit --
 247super aquam refectionis educavit me,
 248>>>>>>>>>> new9.txt
 249animam meam convertit,
 250deduxit me super semitas jusitiae,
 251propter nomen suum.
 252Nam et si ambulavero in medio umbrae mortis,
 253non timebo mala, quoniam TU mecum es:
 254virga tua et baculus tuus ipsa me consolata sunt.
 255EOF
 256
 257test_expect_success 'marker size' '
 258        test_must_fail git merge-file -p --marker-size=10 \
 259                new8.txt new5.txt new9.txt >actual &&
 260        test_cmp expect actual
 261'
 262
 263test_done