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