Mercurial > hg
annotate hgmerge @ 303:15a9e55e7ea5
Check if $DISPLAY is set before using tkdiff or kdiff3.
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 10 Jun 2005 07:50:20 +0100 |
parents | a69c3b2957d1 |
children | 38fb7d23b78d |
rev | line source |
---|---|
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 | |
303
15a9e55e7ea5
Check if $DISPLAY is set before using tkdiff or kdiff3.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
280
diff
changeset
|
32 if [ -n "$DISPLAY" ]; then |
15a9e55e7ea5
Check if $DISPLAY is set before using tkdiff or kdiff3.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
280
diff
changeset
|
33 # try using kdiff3, which is fairly nice |
15a9e55e7ea5
Check if $DISPLAY is set before using tkdiff or kdiff3.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
280
diff
changeset
|
34 if which kdiff3 > /dev/null ; then |
15a9e55e7ea5
Check if $DISPLAY is set before using tkdiff or kdiff3.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
280
diff
changeset
|
35 if kdiff3 --auto $BASE $LOCAL $OTHER -o $LOCAL ; then |
15a9e55e7ea5
Check if $DISPLAY is set before using tkdiff or kdiff3.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
280
diff
changeset
|
36 exit 0 |
15a9e55e7ea5
Check if $DISPLAY is set before using tkdiff or kdiff3.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
280
diff
changeset
|
37 else |
15a9e55e7ea5
Check if $DISPLAY is set before using tkdiff or kdiff3.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
280
diff
changeset
|
38 exit 1 |
15a9e55e7ea5
Check if $DISPLAY is set before using tkdiff or kdiff3.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
280
diff
changeset
|
39 fi |
240 | 40 fi |
41 | |
303
15a9e55e7ea5
Check if $DISPLAY is set before using tkdiff or kdiff3.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
280
diff
changeset
|
42 # try using tkdiff, which is a bit less sophisticated |
15a9e55e7ea5
Check if $DISPLAY is set before using tkdiff or kdiff3.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
280
diff
changeset
|
43 if which tkdiff > /dev/null ; then |
15a9e55e7ea5
Check if $DISPLAY is set before using tkdiff or kdiff3.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
280
diff
changeset
|
44 if tkdiff $LOCAL $OTHER -a $BASE -o $LOCAL ; then |
15a9e55e7ea5
Check if $DISPLAY is set before using tkdiff or kdiff3.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
280
diff
changeset
|
45 exit 0 |
15a9e55e7ea5
Check if $DISPLAY is set before using tkdiff or kdiff3.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
280
diff
changeset
|
46 else |
15a9e55e7ea5
Check if $DISPLAY is set before using tkdiff or kdiff3.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
280
diff
changeset
|
47 exit 1 |
15a9e55e7ea5
Check if $DISPLAY is set before using tkdiff or kdiff3.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
280
diff
changeset
|
48 fi |
240 | 49 fi |
50 fi | |
51 | |
52 # Attempt to do a merge with $EDITOR | |
53 if which merge > /dev/null ; then | |
54 echo "conflicts detected in $LOCAL" | |
55 merge $LOCAL $BASE $OTHER 2>/dev/null || $EDITOR $LOCAL | |
242 | 56 exit 0 |
57 fi | |
58 | |
59 if which diff3 > /dev/null ; then | |
60 echo "conflicts detected in $LOCAL" | |
61 diff3 -m $LOCAL.orig $BASE $OTHER > $LOCAL || $EDITOR $LOCAL | |
62 exit 0 | |
240 | 63 fi |
64 | |
65 # attempt to manually merge with diff and patch | |
66 if which diff > /dev/null ; then | |
67 if which patch > /dev/null ; then | |
68 T=`mktemp` | |
69 diff -u $BASE $OTHER > $T | |
70 if patch $LOCAL < $T ; then | |
71 exit 0 | |
72 else | |
73 $EDITOR $LOCAL $LOCAL.rej | |
74 fi | |
75 rm $T | |
76 exit 1 | |
77 fi | |
78 fi | |
79 | |
80 echo "hgmerge: unable to find merge, tkdiff, kdiff3, or diff+patch!" | |
81 exit 1 |