##// END OF EJS Templates
hgmerge: use diff3 if available...
mpm@selenic.com -
r242:a2edb448 default
parent child Browse files
Show More
@@ -1,68 +1,79 b''
1 #!/bin/bash
1 #!/bin/bash
2 #
2 #
3 # hgmerge - default merge helper for Mercurial
3 # hgmerge - default merge helper for Mercurial
4 #
4 #
5 # This tries to find a way to do three-way merge on the current system.
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.
6 # The result ought to end up in $1.
7
7
8 set -e # bail out quickly on failure
8 set -e # bail out quickly on failure
9
9
10 LOCAL=$1
10 LOCAL=$1
11 BASE=$2
11 BASE=$2
12 OTHER=$3
12 OTHER=$3
13
13
14 # Back up our file
14 # Back up our file
15 cp $LOCAL $LOCAL.orig
15 cp $LOCAL $LOCAL.orig
16
16
17 # Attempt to do a non-interactive merge
17 # Attempt to do a non-interactive merge
18 if which merge > /dev/null ; then
18 if which merge > /dev/null ; then
19 if merge $LOCAL $BASE $OTHER 2> /dev/null; then
19 if merge $LOCAL $BASE $OTHER 2> /dev/null; then
20 # success!
20 # success!
21 exit 0
21 exit 0
22 fi
22 fi
23 cp $LOCAL.orig $LOCAL
23 cp $LOCAL.orig $LOCAL
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
24 fi
30 fi
25
31
26 # try using kdiff3, which is fairly nice
32 # try using kdiff3, which is fairly nice
27 if which kdiff3 > /dev/null ; then
33 if which kdiff3 > /dev/null ; then
28 if kdiff3 --auto $BASE $LOCAL $OTHER -o $LOCAL ; then
34 if kdiff3 --auto $BASE $LOCAL $OTHER -o $LOCAL ; then
29 exit 0
35 exit 0
30 else
36 else
31 exit 1
37 exit 1
32 fi
38 fi
33 fi
39 fi
34
40
35 # try using tkdiff, which is a bit less sophisticated
41 # try using tkdiff, which is a bit less sophisticated
36 if which tkdiff > /dev/null ; then
42 if which tkdiff > /dev/null ; then
37 if tkdiff $LOCAL $OTHER -a $BASE -o $LOCAL ; then
43 if tkdiff $LOCAL $OTHER -a $BASE -o $LOCAL ; then
38 exit 0
44 exit 0
39 else
45 else
40 exit 1
46 exit 1
41 fi
47 fi
42 fi
48 fi
43
49
44 # Attempt to do a merge with $EDITOR
50 # Attempt to do a merge with $EDITOR
45 if which merge > /dev/null ; then
51 if which merge > /dev/null ; then
46 echo "conflicts detected in $LOCAL"
52 echo "conflicts detected in $LOCAL"
47 merge $LOCAL $BASE $OTHER 2>/dev/null || $EDITOR $LOCAL
53 merge $LOCAL $BASE $OTHER 2>/dev/null || $EDITOR $LOCAL
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
48 fi
61 fi
49
62
50 # attempt to manually merge with diff and patch
63 # attempt to manually merge with diff and patch
51 if which diff > /dev/null ; then
64 if which diff > /dev/null ; then
52 if which patch > /dev/null ; then
65 if which patch > /dev/null ; then
53 T=`mktemp`
66 T=`mktemp`
54 diff -u $BASE $OTHER > $T
67 diff -u $BASE $OTHER > $T
55 if patch $LOCAL < $T ; then
68 if patch $LOCAL < $T ; then
56 exit 0
69 exit 0
57 else
70 else
58 $EDITOR $LOCAL $LOCAL.rej
71 $EDITOR $LOCAL $LOCAL.rej
59 fi
72 fi
60 rm $T
73 rm $T
61 exit 1
74 exit 1
62 fi
75 fi
63 fi
76 fi
64
77
65 echo "hgmerge: unable to find merge, tkdiff, kdiff3, or diff+patch!"
78 echo "hgmerge: unable to find merge, tkdiff, kdiff3, or diff+patch!"
66 exit 1
79 exit 1
67
68
General Comments 0
You need to be logged in to leave comments. Login now