Show More
@@ -1,79 +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 | # try using kdiff3, which is fairly nice |
|
34 | if [ -n "$DISPLAY" ]; then | |
33 | if which kdiff3 > /dev/null ; then |
|
35 | # try using kdiff3, which is fairly nice | |
34 | if kdiff3 --auto $BASE $LOCAL $OTHER -o $LOCAL ; then |
|
36 | if which kdiff3 > /dev/null ; then | |
35 | exit 0 |
|
37 | if kdiff3 --auto $BASE $LOCAL $OTHER -o $LOCAL ; then | |
36 | else |
|
38 | exit 0 | |
37 | exit 1 |
|
39 | else | |
|
40 | exit 1 | |||
|
41 | fi | |||
38 | fi |
|
42 | fi | |
39 | fi |
|
|||
40 |
|
43 | |||
41 | # try using tkdiff, which is a bit less sophisticated |
|
44 | # try using tkdiff, which is a bit less sophisticated | |
42 | if which tkdiff > /dev/null ; then |
|
45 | if which tkdiff > /dev/null ; then | |
43 |
|
|
46 | if tkdiff $LOCAL $OTHER -a $BASE -o $LOCAL ; then | |
44 | exit 0 |
|
47 | exit 0 | |
45 |
|
|
48 | else | |
46 | exit 1 |
|
49 | exit 1 | |
|
50 | fi | |||
47 | fi |
|
51 | fi | |
48 | fi |
|
52 | fi | |
49 |
|
53 | |||
50 | # Attempt to do a merge with $EDITOR |
|
54 | # Attempt to do a merge with $EDITOR | |
51 | if which merge > /dev/null ; then |
|
55 | if which merge > /dev/null ; then | |
52 | echo "conflicts detected in $LOCAL" |
|
56 | echo "conflicts detected in $LOCAL" | |
53 | merge $LOCAL $BASE $OTHER 2>/dev/null || $EDITOR $LOCAL |
|
57 | merge $LOCAL $BASE $OTHER 2>/dev/null || $EDITOR $LOCAL | |
54 | exit 0 |
|
58 | exit 0 | |
55 | fi |
|
59 | fi | |
56 |
|
60 | |||
57 | if which diff3 > /dev/null ; then |
|
61 | if which diff3 > /dev/null ; then | |
58 | echo "conflicts detected in $LOCAL" |
|
62 | echo "conflicts detected in $LOCAL" | |
59 | diff3 -m $LOCAL.orig $BASE $OTHER > $LOCAL || $EDITOR $LOCAL |
|
63 | diff3 -m $LOCAL.orig $BASE $OTHER > $LOCAL || $EDITOR $LOCAL | |
60 | exit 0 |
|
64 | exit 0 | |
61 | fi |
|
65 | fi | |
62 |
|
66 | |||
63 | # attempt to manually merge with diff and patch |
|
67 | # attempt to manually merge with diff and patch | |
64 | if which diff > /dev/null ; then |
|
68 | if which diff > /dev/null ; then | |
65 | if which patch > /dev/null ; then |
|
69 | if which patch > /dev/null ; then | |
66 | T=`mktemp` |
|
70 | T=`mktemp` | |
67 | diff -u $BASE $OTHER > $T |
|
71 | diff -u $BASE $OTHER > $T | |
68 | if patch $LOCAL < $T ; then |
|
72 | if patch $LOCAL < $T ; then | |
69 | exit 0 |
|
73 | exit 0 | |
70 | else |
|
74 | else | |
71 | $EDITOR $LOCAL $LOCAL.rej |
|
75 | $EDITOR $LOCAL $LOCAL.rej | |
72 | fi |
|
76 | fi | |
73 | rm $T |
|
77 | rm $T | |
74 | exit 1 |
|
78 | exit 1 | |
75 | fi |
|
79 | fi | |
76 | fi |
|
80 | fi | |
77 |
|
81 | |||
78 | echo "hgmerge: unable to find merge, tkdiff, kdiff3, or diff+patch!" |
|
82 | echo "hgmerge: unable to find merge, tkdiff, kdiff3, or diff+patch!" | |
79 | exit 1 |
|
83 | exit 1 |
General Comments 0
You need to be logged in to leave comments.
Login now