hgmerge
changeset 240 737c66b68290
child 242 a2edb4481f19
equal deleted inserted replaced
239:75840796e8e2 240:737c66b68290
       
     1 #!/bin/bash
       
     2 #
       
     3 # hgmerge - default merge helper for Mercurial
       
     4 #
       
     5 # This tries to find a way to do three-way merge on the current system.
       
     6 # The result ought to end up in $1.
       
     7 
       
     8 set -e # bail out quickly on failure
       
     9 
       
    10 LOCAL=$1
       
    11 BASE=$2
       
    12 OTHER=$3
       
    13 
       
    14 # Back up our file
       
    15 cp $LOCAL $LOCAL.orig
       
    16 
       
    17 # Attempt to do a non-interactive merge
       
    18 if which merge > /dev/null ; then
       
    19     if merge $LOCAL $BASE $OTHER 2> /dev/null; then
       
    20 	# success!
       
    21 	exit 0
       
    22     fi
       
    23     cp $LOCAL.orig $LOCAL
       
    24 fi
       
    25 
       
    26 # try using kdiff3, which is fairly nice
       
    27 if which kdiff3 > /dev/null ; then
       
    28     if kdiff3 --auto $BASE $LOCAL $OTHER -o $LOCAL ; then
       
    29 	exit 0
       
    30     else
       
    31 	exit 1
       
    32     fi
       
    33 fi
       
    34 
       
    35 # try using tkdiff, which is a bit less sophisticated
       
    36 if which tkdiff > /dev/null ; then
       
    37     if tkdiff $LOCAL $OTHER -a $BASE -o $LOCAL ; then
       
    38 	exit 0
       
    39     else
       
    40 	exit 1
       
    41     fi
       
    42 fi
       
    43 
       
    44 # Attempt to do a merge with $EDITOR
       
    45 if which merge > /dev/null ; then
       
    46     echo "conflicts detected in $LOCAL"
       
    47     merge $LOCAL $BASE $OTHER 2>/dev/null || $EDITOR $LOCAL
       
    48 fi
       
    49 
       
    50 # attempt to manually merge with diff and patch
       
    51 if which diff > /dev/null ; then
       
    52     if which patch > /dev/null ; then
       
    53 	T=`mktemp`
       
    54 	diff -u $BASE $OTHER > $T
       
    55 	if patch $LOCAL < $T ; then
       
    56 	    exit 0
       
    57 	else
       
    58 	    $EDITOR $LOCAL $LOCAL.rej
       
    59 	fi
       
    60 	rm $T
       
    61 	exit 1
       
    62     fi
       
    63 fi
       
    64 
       
    65 echo "hgmerge: unable to find merge, tkdiff, kdiff3, or diff+patch!"
       
    66 exit 1
       
    67 
       
    68