##// END OF EJS Templates
Use vi if $EDITOR is unset.
Thomas Arendsen Hein -
r304:38fb7d23 default
parent child Browse files
Show More
@@ -1,81 +1,83 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 EDITOR="${EDITOR:-vi}"
15
14 # Back up our file
16 # Back up our file
15 cp $LOCAL $LOCAL.orig
17 cp $LOCAL $LOCAL.orig
16
18
17 # Attempt to do a non-interactive merge
19 # Attempt to do a non-interactive merge
18 if which merge > /dev/null ; then
20 if which merge > /dev/null ; then
19 if merge $LOCAL $BASE $OTHER 2> /dev/null; then
21 if merge $LOCAL $BASE $OTHER 2> /dev/null; then
20 # success!
22 # success!
21 exit 0
23 exit 0
22 fi
24 fi
23 cp $LOCAL.orig $LOCAL
25 cp $LOCAL.orig $LOCAL
24 elif which diff3 > /dev/null ; then
26 elif which diff3 > /dev/null ; then
25 if diff3 -m $LOCAL.orig $BASE $OTHER > $LOCAL ; then
27 if diff3 -m $LOCAL.orig $BASE $OTHER > $LOCAL ; then
26 # success
28 # success
27 exit 0
29 exit 0
28 fi
30 fi
29 cp $LOCAL.orig $LOCAL
31 cp $LOCAL.orig $LOCAL
30 fi
32 fi
31
33
32 if [ -n "$DISPLAY" ]; then
34 if [ -n "$DISPLAY" ]; then
33 # try using kdiff3, which is fairly nice
35 # try using kdiff3, which is fairly nice
34 if which kdiff3 > /dev/null ; then
36 if which kdiff3 > /dev/null ; then
35 if kdiff3 --auto $BASE $LOCAL $OTHER -o $LOCAL ; then
37 if kdiff3 --auto $BASE $LOCAL $OTHER -o $LOCAL ; then
36 exit 0
38 exit 0
37 else
39 else
38 exit 1
40 exit 1
39 fi
41 fi
40 fi
42 fi
41
43
42 # try using tkdiff, which is a bit less sophisticated
44 # try using tkdiff, which is a bit less sophisticated
43 if which tkdiff > /dev/null ; then
45 if which tkdiff > /dev/null ; then
44 if tkdiff $LOCAL $OTHER -a $BASE -o $LOCAL ; then
46 if tkdiff $LOCAL $OTHER -a $BASE -o $LOCAL ; then
45 exit 0
47 exit 0
46 else
48 else
47 exit 1
49 exit 1
48 fi
50 fi
49 fi
51 fi
50 fi
52 fi
51
53
52 # Attempt to do a merge with $EDITOR
54 # Attempt to do a merge with $EDITOR
53 if which merge > /dev/null ; then
55 if which merge > /dev/null ; then
54 echo "conflicts detected in $LOCAL"
56 echo "conflicts detected in $LOCAL"
55 merge $LOCAL $BASE $OTHER 2>/dev/null || $EDITOR $LOCAL
57 merge $LOCAL $BASE $OTHER 2>/dev/null || $EDITOR $LOCAL
56 exit 0
58 exit 0
57 fi
59 fi
58
60
59 if which diff3 > /dev/null ; then
61 if which diff3 > /dev/null ; then
60 echo "conflicts detected in $LOCAL"
62 echo "conflicts detected in $LOCAL"
61 diff3 -m $LOCAL.orig $BASE $OTHER > $LOCAL || $EDITOR $LOCAL
63 diff3 -m $LOCAL.orig $BASE $OTHER > $LOCAL || $EDITOR $LOCAL
62 exit 0
64 exit 0
63 fi
65 fi
64
66
65 # attempt to manually merge with diff and patch
67 # attempt to manually merge with diff and patch
66 if which diff > /dev/null ; then
68 if which diff > /dev/null ; then
67 if which patch > /dev/null ; then
69 if which patch > /dev/null ; then
68 T=`mktemp`
70 T=`mktemp`
69 diff -u $BASE $OTHER > $T
71 diff -u $BASE $OTHER > $T
70 if patch $LOCAL < $T ; then
72 if patch $LOCAL < $T ; then
71 exit 0
73 exit 0
72 else
74 else
73 $EDITOR $LOCAL $LOCAL.rej
75 $EDITOR $LOCAL $LOCAL.rej
74 fi
76 fi
75 rm $T
77 rm $T
76 exit 1
78 exit 1
77 fi
79 fi
78 fi
80 fi
79
81
80 echo "hgmerge: unable to find merge, tkdiff, kdiff3, or diff+patch!"
82 echo "hgmerge: unable to find merge, tkdiff, kdiff3, or diff+patch!"
81 exit 1
83 exit 1
General Comments 0
You need to be logged in to leave comments. Login now