hgmerge
author mpm@selenic.com
Fri, 03 Jun 2005 18:27:55 -0800
changeset 240 737c66b68290
child 242 a2edb4481f19
permissions -rw-r--r--
Replace tkmerge with hgmerge -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Replace tkmerge with hgmerge hgmerge attempts to find and use merge, kdiff3, tkmerge, and diff+patch. hg will use hgmerge unless overridden with HGMERGE manifest hash: 9137a620df4b235e66343b0fd0dba87fe631546e -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCoRGrywK+sNU5EO8RAi2VAJ9bh97ChGJymP/p8rvCuyNAMnk1bQCgrIGP vYI6qlyWKQZ01ObUTAIg92o= =+mRH -----END PGP SIGNATURE-----
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
240
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
     1
#!/bin/bash
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
     2
#
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
     3
# hgmerge - default merge helper for Mercurial
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
     4
#
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
     5
# This tries to find a way to do three-way merge on the current system.
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
     6
# The result ought to end up in $1.
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
     7
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
     8
set -e # bail out quickly on failure
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
     9
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    10
LOCAL=$1
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    11
BASE=$2
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    12
OTHER=$3
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    13
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    14
# Back up our file
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    15
cp $LOCAL $LOCAL.orig
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    16
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    17
# Attempt to do a non-interactive merge
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    18
if which merge > /dev/null ; then
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    19
    if merge $LOCAL $BASE $OTHER 2> /dev/null; then
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    20
	# success!
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    21
	exit 0
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    22
    fi
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    23
    cp $LOCAL.orig $LOCAL
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    24
fi
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    25
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    26
# try using kdiff3, which is fairly nice
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    27
if which kdiff3 > /dev/null ; then
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    28
    if kdiff3 --auto $BASE $LOCAL $OTHER -o $LOCAL ; then
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    29
	exit 0
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    30
    else
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    31
	exit 1
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    32
    fi
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    33
fi
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    34
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    35
# try using tkdiff, which is a bit less sophisticated
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    36
if which tkdiff > /dev/null ; then
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    37
    if tkdiff $LOCAL $OTHER -a $BASE -o $LOCAL ; then
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    38
	exit 0
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    39
    else
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    40
	exit 1
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    41
    fi
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    42
fi
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    43
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    44
# Attempt to do a merge with $EDITOR
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    45
if which merge > /dev/null ; then
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    46
    echo "conflicts detected in $LOCAL"
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    47
    merge $LOCAL $BASE $OTHER 2>/dev/null || $EDITOR $LOCAL
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    48
fi
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    49
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    50
# attempt to manually merge with diff and patch
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    51
if which diff > /dev/null ; then
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    52
    if which patch > /dev/null ; then
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    53
	T=`mktemp`
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    54
	diff -u $BASE $OTHER > $T
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    55
	if patch $LOCAL < $T ; then
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    56
	    exit 0
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    57
	else
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    58
	    $EDITOR $LOCAL $LOCAL.rej
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    59
	fi
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    60
	rm $T
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    61
	exit 1
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    62
    fi
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    63
fi
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    64
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    65
echo "hgmerge: unable to find merge, tkdiff, kdiff3, or diff+patch!"
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    66
exit 1
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    67
737c66b68290 Replace tkmerge with hgmerge
mpm@selenic.com
parents:
diff changeset
    68