240
|
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
|
242
|
24 elif which diff3 > /dev/null ; then
|
|
25 if diff3 -m $LOCAL.orig $BASE $OTHER > $LOCAL ; then
|
|
26 # success
|
|
27 exit 0
|
|
28 fi
|
|
29 cp $LOCAL.orig $LOCAL
|
240
|
30 fi
|
|
31
|
|
32 # try using kdiff3, which is fairly nice
|
|
33 if which kdiff3 > /dev/null ; then
|
|
34 if kdiff3 --auto $BASE $LOCAL $OTHER -o $LOCAL ; then
|
|
35 exit 0
|
|
36 else
|
|
37 exit 1
|
|
38 fi
|
|
39 fi
|
|
40
|
|
41 # try using tkdiff, which is a bit less sophisticated
|
|
42 if which tkdiff > /dev/null ; then
|
|
43 if tkdiff $LOCAL $OTHER -a $BASE -o $LOCAL ; then
|
|
44 exit 0
|
|
45 else
|
|
46 exit 1
|
|
47 fi
|
|
48 fi
|
|
49
|
|
50 # Attempt to do a merge with $EDITOR
|
|
51 if which merge > /dev/null ; then
|
|
52 echo "conflicts detected in $LOCAL"
|
|
53 merge $LOCAL $BASE $OTHER 2>/dev/null || $EDITOR $LOCAL
|
242
|
54 exit 0
|
|
55 fi
|
|
56
|
|
57 if which diff3 > /dev/null ; then
|
|
58 echo "conflicts detected in $LOCAL"
|
|
59 diff3 -m $LOCAL.orig $BASE $OTHER > $LOCAL || $EDITOR $LOCAL
|
|
60 exit 0
|
240
|
61 fi
|
|
62
|
|
63 # attempt to manually merge with diff and patch
|
|
64 if which diff > /dev/null ; then
|
|
65 if which patch > /dev/null ; then
|
|
66 T=`mktemp`
|
|
67 diff -u $BASE $OTHER > $T
|
|
68 if patch $LOCAL < $T ; then
|
|
69 exit 0
|
|
70 else
|
|
71 $EDITOR $LOCAL $LOCAL.rej
|
|
72 fi
|
|
73 rm $T
|
|
74 exit 1
|
|
75 fi
|
|
76 fi
|
|
77
|
|
78 echo "hgmerge: unable to find merge, tkdiff, kdiff3, or diff+patch!"
|
|
79 exit 1
|