author | Thomas Arendsen Hein <thomas@intevation.de> |
Fri, 07 Sep 2007 16:14:51 +0200 | |
changeset 5287 | c6f932d3e0f6 |
parent 5172 | f53d97d651f4 |
child 5660 | 3c80ecdc1bcd |
permissions | -rwxr-xr-x |
544
3d4d5f2aba9a
Remove bashisms and use /bin/sh instead of /bin/bash.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
306
diff
changeset
|
1 |
#!/bin/sh |
240 | 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. |
|
1885
c4d577262d00
run merge program in repo root.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1884
diff
changeset
|
6 |
# The result ought to end up in $1. Script is run in root directory of |
c4d577262d00
run merge program in repo root.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1884
diff
changeset
|
7 |
# repository. |
1883
b98160cfb2f3
give more info to hgmerge script.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1880
diff
changeset
|
8 |
# |
b98160cfb2f3
give more info to hgmerge script.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1880
diff
changeset
|
9 |
# Environment variables set by Mercurial: |
b98160cfb2f3
give more info to hgmerge script.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1880
diff
changeset
|
10 |
# HG_FILE name of file within repo |
b98160cfb2f3
give more info to hgmerge script.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1880
diff
changeset
|
11 |
# HG_MY_NODE revision being merged |
b98160cfb2f3
give more info to hgmerge script.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1880
diff
changeset
|
12 |
# HG_OTHER_NODE revision being merged |
240 | 13 |
|
14 |
set -e # bail out quickly on failure |
|
15 |
||
795
cd0ad12d9e42
Remove usage of ${par:-word}, which and mktemp. Quote filenames.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
547
diff
changeset
|
16 |
LOCAL="$1" |
cd0ad12d9e42
Remove usage of ${par:-word}, which and mktemp. Quote filenames.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
547
diff
changeset
|
17 |
BASE="$2" |
cd0ad12d9e42
Remove usage of ${par:-word}, which and mktemp. Quote filenames.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
547
diff
changeset
|
18 |
OTHER="$3" |
240 | 19 |
|
795
cd0ad12d9e42
Remove usage of ${par:-word}, which and mktemp. Quote filenames.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
547
diff
changeset
|
20 |
if [ -z "$EDITOR" ]; then |
cd0ad12d9e42
Remove usage of ${par:-word}, which and mktemp. Quote filenames.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
547
diff
changeset
|
21 |
EDITOR="vi" |
cd0ad12d9e42
Remove usage of ${par:-word}, which and mktemp. Quote filenames.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
547
diff
changeset
|
22 |
fi |
304
38fb7d23b78d
Use vi if $EDITOR is unset.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
303
diff
changeset
|
23 |
|
1434
696851b1bba9
Fix use of diff(1) triggered by set -e.
levon@movementarian.org
parents:
839
diff
changeset
|
24 |
# find decent versions of our utilities, insisting on the GNU versions where we |
696851b1bba9
Fix use of diff(1) triggered by set -e.
levon@movementarian.org
parents:
839
diff
changeset
|
25 |
# need to |
1770
4eea6a747c27
hgmerge: fix diff+patch detection; cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1701
diff
changeset
|
26 |
MERGE="merge" |
4eea6a747c27
hgmerge: fix diff+patch detection; cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1701
diff
changeset
|
27 |
DIFF3="gdiff3" |
4eea6a747c27
hgmerge: fix diff+patch detection; cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1701
diff
changeset
|
28 |
DIFF="gdiff" |
4eea6a747c27
hgmerge: fix diff+patch detection; cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1701
diff
changeset
|
29 |
PATCH="gpatch" |
1434
696851b1bba9
Fix use of diff(1) triggered by set -e.
levon@movementarian.org
parents:
839
diff
changeset
|
30 |
|
1770
4eea6a747c27
hgmerge: fix diff+patch detection; cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1701
diff
changeset
|
31 |
type "$MERGE" >/dev/null 2>&1 || MERGE= |
4eea6a747c27
hgmerge: fix diff+patch detection; cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1701
diff
changeset
|
32 |
type "$DIFF3" >/dev/null 2>&1 || DIFF3="diff3" |
1434
696851b1bba9
Fix use of diff(1) triggered by set -e.
levon@movementarian.org
parents:
839
diff
changeset
|
33 |
$DIFF3 --version >/dev/null 2>&1 || DIFF3= |
1770
4eea6a747c27
hgmerge: fix diff+patch detection; cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1701
diff
changeset
|
34 |
type "$DIFF" >/dev/null 2>&1 || DIFF="diff" |
4eea6a747c27
hgmerge: fix diff+patch detection; cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1701
diff
changeset
|
35 |
type "$DIFF" >/dev/null 2>&1 || DIFF= |
4eea6a747c27
hgmerge: fix diff+patch detection; cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1701
diff
changeset
|
36 |
type "$PATCH" >/dev/null 2>&1 || PATCH="patch" |
4eea6a747c27
hgmerge: fix diff+patch detection; cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1701
diff
changeset
|
37 |
type "$PATCH" >/dev/null 2>&1 || PATCH= |
1434
696851b1bba9
Fix use of diff(1) triggered by set -e.
levon@movementarian.org
parents:
839
diff
changeset
|
38 |
|
1699
83e8cd97b9f9
hgmerge: add and use more tool variables
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1664
diff
changeset
|
39 |
# find optional visual utilities |
1770
4eea6a747c27
hgmerge: fix diff+patch detection; cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1701
diff
changeset
|
40 |
FILEMERGE="/Developer/Applications/Utilities/FileMerge.app/Contents/MacOS/FileMerge" |
4eea6a747c27
hgmerge: fix diff+patch detection; cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1701
diff
changeset
|
41 |
KDIFF3="kdiff3" |
4eea6a747c27
hgmerge: fix diff+patch detection; cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1701
diff
changeset
|
42 |
TKDIFF="tkdiff" |
1774
ac7b91bcbd8d
hgmerge: add meld support
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1773
diff
changeset
|
43 |
MELD="meld" |
1699
83e8cd97b9f9
hgmerge: add and use more tool variables
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1664
diff
changeset
|
44 |
|
1770
4eea6a747c27
hgmerge: fix diff+patch detection; cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1701
diff
changeset
|
45 |
type "$FILEMERGE" >/dev/null 2>&1 || FILEMERGE= |
4eea6a747c27
hgmerge: fix diff+patch detection; cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1701
diff
changeset
|
46 |
type "$KDIFF3" >/dev/null 2>&1 || KDIFF3= |
4eea6a747c27
hgmerge: fix diff+patch detection; cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1701
diff
changeset
|
47 |
type "$TKDIFF" >/dev/null 2>&1 || TKDIFF= |
1774
ac7b91bcbd8d
hgmerge: add meld support
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1773
diff
changeset
|
48 |
type "$MELD" >/dev/null 2>&1 || MELD= |
1699
83e8cd97b9f9
hgmerge: add and use more tool variables
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1664
diff
changeset
|
49 |
|
2051
6a03cff2b0f5
Try to use /usr/bin/test or /bin/test to work around missing features.
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1885
diff
changeset
|
50 |
# Hack for Solaris |
6a03cff2b0f5
Try to use /usr/bin/test or /bin/test to work around missing features.
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1885
diff
changeset
|
51 |
TEST="/usr/bin/test" |
6a03cff2b0f5
Try to use /usr/bin/test or /bin/test to work around missing features.
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1885
diff
changeset
|
52 |
type "$TEST" >/dev/null 2>&1 || TEST="/bin/test" |
6a03cff2b0f5
Try to use /usr/bin/test or /bin/test to work around missing features.
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1885
diff
changeset
|
53 |
type "$TEST" >/dev/null 2>&1 || TEST="test" |
6a03cff2b0f5
Try to use /usr/bin/test or /bin/test to work around missing features.
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1885
diff
changeset
|
54 |
|
1701
4ba8fe499df2
hgmerge: various cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1700
diff
changeset
|
55 |
# random part of names |
1770
4eea6a747c27
hgmerge: fix diff+patch detection; cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1701
diff
changeset
|
56 |
RAND="$RANDOM$RANDOM" |
1701
4ba8fe499df2
hgmerge: various cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1700
diff
changeset
|
57 |
|
1700
e2f91e0acbb8
hgmerge: add cleanup functions
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1699
diff
changeset
|
58 |
# temporary directory for diff+patch merge |
1797
42f75cd04bf4
Fix hgmerge: mkdir "'/tmp'/hgmerge..." and ask_if_merged() didn't work.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1774
diff
changeset
|
59 |
HGTMP="${TMPDIR-/tmp}/hgmerge.$RAND" |
1701
4ba8fe499df2
hgmerge: various cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1700
diff
changeset
|
60 |
|
4ba8fe499df2
hgmerge: various cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1700
diff
changeset
|
61 |
# backup file |
4ba8fe499df2
hgmerge: various cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1700
diff
changeset
|
62 |
BACKUP="$LOCAL.orig.$RAND" |
4ba8fe499df2
hgmerge: various cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1700
diff
changeset
|
63 |
|
4ba8fe499df2
hgmerge: various cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1700
diff
changeset
|
64 |
# file used to test for file change |
4ba8fe499df2
hgmerge: various cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1700
diff
changeset
|
65 |
CHGTEST="$LOCAL.chg.$RAND" |
1700
e2f91e0acbb8
hgmerge: add cleanup functions
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1699
diff
changeset
|
66 |
|
e2f91e0acbb8
hgmerge: add cleanup functions
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1699
diff
changeset
|
67 |
# put all your required cleanup here |
e2f91e0acbb8
hgmerge: add cleanup functions
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1699
diff
changeset
|
68 |
cleanup() { |
1701
4ba8fe499df2
hgmerge: various cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1700
diff
changeset
|
69 |
rm -f "$BACKUP" "$CHGTEST" |
1700
e2f91e0acbb8
hgmerge: add cleanup functions
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1699
diff
changeset
|
70 |
rm -rf "$HGTMP" |
e2f91e0acbb8
hgmerge: add cleanup functions
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1699
diff
changeset
|
71 |
} |
e2f91e0acbb8
hgmerge: add cleanup functions
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1699
diff
changeset
|
72 |
|
e2f91e0acbb8
hgmerge: add cleanup functions
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1699
diff
changeset
|
73 |
# functions concerning program exit |
e2f91e0acbb8
hgmerge: add cleanup functions
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1699
diff
changeset
|
74 |
success() { |
e2f91e0acbb8
hgmerge: add cleanup functions
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1699
diff
changeset
|
75 |
cleanup |
e2f91e0acbb8
hgmerge: add cleanup functions
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1699
diff
changeset
|
76 |
exit 0 |
e2f91e0acbb8
hgmerge: add cleanup functions
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1699
diff
changeset
|
77 |
} |
e2f91e0acbb8
hgmerge: add cleanup functions
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1699
diff
changeset
|
78 |
|
e2f91e0acbb8
hgmerge: add cleanup functions
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1699
diff
changeset
|
79 |
failure() { |
e2f91e0acbb8
hgmerge: add cleanup functions
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1699
diff
changeset
|
80 |
echo "merge failed" 1>&2 |
1701
4ba8fe499df2
hgmerge: various cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1700
diff
changeset
|
81 |
mv "$BACKUP" "$LOCAL" |
1700
e2f91e0acbb8
hgmerge: add cleanup functions
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1699
diff
changeset
|
82 |
cleanup |
e2f91e0acbb8
hgmerge: add cleanup functions
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1699
diff
changeset
|
83 |
exit 1 |
e2f91e0acbb8
hgmerge: add cleanup functions
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1699
diff
changeset
|
84 |
} |
e2f91e0acbb8
hgmerge: add cleanup functions
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1699
diff
changeset
|
85 |
|
1771
e22bbca2e82b
hgmerge: add and use ask_if_merged function
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1770
diff
changeset
|
86 |
# Ask if the merge was successful |
e22bbca2e82b
hgmerge: add and use ask_if_merged function
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1770
diff
changeset
|
87 |
ask_if_merged() { |
1797
42f75cd04bf4
Fix hgmerge: mkdir "'/tmp'/hgmerge..." and ask_if_merged() didn't work.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1774
diff
changeset
|
88 |
while true; do |
42f75cd04bf4
Fix hgmerge: mkdir "'/tmp'/hgmerge..." and ask_if_merged() didn't work.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1774
diff
changeset
|
89 |
echo "$LOCAL seems unchanged." |
42f75cd04bf4
Fix hgmerge: mkdir "'/tmp'/hgmerge..." and ask_if_merged() didn't work.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1774
diff
changeset
|
90 |
echo "Was the merge successful? [y/n]" |
1771
e22bbca2e82b
hgmerge: add and use ask_if_merged function
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1770
diff
changeset
|
91 |
read answer |
1797
42f75cd04bf4
Fix hgmerge: mkdir "'/tmp'/hgmerge..." and ask_if_merged() didn't work.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1774
diff
changeset
|
92 |
case "$answer" in |
1771
e22bbca2e82b
hgmerge: add and use ask_if_merged function
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1770
diff
changeset
|
93 |
y*|Y*) success;; |
e22bbca2e82b
hgmerge: add and use ask_if_merged function
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1770
diff
changeset
|
94 |
n*|N*) failure;; |
e22bbca2e82b
hgmerge: add and use ask_if_merged function
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1770
diff
changeset
|
95 |
esac |
e22bbca2e82b
hgmerge: add and use ask_if_merged function
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1770
diff
changeset
|
96 |
done |
e22bbca2e82b
hgmerge: add and use ask_if_merged function
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1770
diff
changeset
|
97 |
} |
e22bbca2e82b
hgmerge: add and use ask_if_merged function
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1770
diff
changeset
|
98 |
|
4855
e4480f2b61e9
Check for conflict markers in hgmerge (issue471)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2051
diff
changeset
|
99 |
# Check if conflict markers are present and ask if the merge was successful |
e4480f2b61e9
Check for conflict markers in hgmerge (issue471)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2051
diff
changeset
|
100 |
conflicts_or_success() { |
e4480f2b61e9
Check for conflict markers in hgmerge (issue471)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2051
diff
changeset
|
101 |
while egrep '^(<<<<<<< .*|=======|>>>>>>> .*)$' "$LOCAL" >/dev/null; do |
e4480f2b61e9
Check for conflict markers in hgmerge (issue471)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2051
diff
changeset
|
102 |
echo "$LOCAL contains conflict markers." |
e4480f2b61e9
Check for conflict markers in hgmerge (issue471)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2051
diff
changeset
|
103 |
echo "Keep this version? [y/n]" |
e4480f2b61e9
Check for conflict markers in hgmerge (issue471)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2051
diff
changeset
|
104 |
read answer |
e4480f2b61e9
Check for conflict markers in hgmerge (issue471)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2051
diff
changeset
|
105 |
case "$answer" in |
e4480f2b61e9
Check for conflict markers in hgmerge (issue471)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2051
diff
changeset
|
106 |
y*|Y*) success;; |
e4480f2b61e9
Check for conflict markers in hgmerge (issue471)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2051
diff
changeset
|
107 |
n*|N*) failure;; |
e4480f2b61e9
Check for conflict markers in hgmerge (issue471)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2051
diff
changeset
|
108 |
esac |
e4480f2b61e9
Check for conflict markers in hgmerge (issue471)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2051
diff
changeset
|
109 |
done |
e4480f2b61e9
Check for conflict markers in hgmerge (issue471)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2051
diff
changeset
|
110 |
success |
e4480f2b61e9
Check for conflict markers in hgmerge (issue471)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2051
diff
changeset
|
111 |
} |
e4480f2b61e9
Check for conflict markers in hgmerge (issue471)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2051
diff
changeset
|
112 |
|
1700
e2f91e0acbb8
hgmerge: add cleanup functions
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1699
diff
changeset
|
113 |
# Clean up when interrupted |
e2f91e0acbb8
hgmerge: add cleanup functions
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1699
diff
changeset
|
114 |
trap "failure" 1 2 3 6 15 # HUP INT QUIT ABRT TERM |
e2f91e0acbb8
hgmerge: add cleanup functions
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1699
diff
changeset
|
115 |
|
1701
4ba8fe499df2
hgmerge: various cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1700
diff
changeset
|
116 |
# Back up our file (and try hard to keep the mtime unchanged) |
4ba8fe499df2
hgmerge: various cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1700
diff
changeset
|
117 |
mv "$LOCAL" "$BACKUP" |
4ba8fe499df2
hgmerge: various cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1700
diff
changeset
|
118 |
cp "$BACKUP" "$LOCAL" |
240 | 119 |
|
120 |
# Attempt to do a non-interactive merge |
|
1770
4eea6a747c27
hgmerge: fix diff+patch detection; cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1701
diff
changeset
|
121 |
if [ -n "$MERGE" -o -n "$DIFF3" ]; then |
4eea6a747c27
hgmerge: fix diff+patch detection; cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1701
diff
changeset
|
122 |
if [ -n "$MERGE" ]; then |
4eea6a747c27
hgmerge: fix diff+patch detection; cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1701
diff
changeset
|
123 |
$MERGE "$LOCAL" "$BASE" "$OTHER" 2> /dev/null && success |
4eea6a747c27
hgmerge: fix diff+patch detection; cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1701
diff
changeset
|
124 |
elif [ -n "$DIFF3" ]; then |
4eea6a747c27
hgmerge: fix diff+patch detection; cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1701
diff
changeset
|
125 |
$DIFF3 -m "$BACKUP" "$BASE" "$OTHER" > "$LOCAL" && success |
4eea6a747c27
hgmerge: fix diff+patch detection; cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1701
diff
changeset
|
126 |
fi |
4eea6a747c27
hgmerge: fix diff+patch detection; cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1701
diff
changeset
|
127 |
if [ $? -gt 1 ]; then |
4eea6a747c27
hgmerge: fix diff+patch detection; cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1701
diff
changeset
|
128 |
echo "automatic merge failed! Exiting." 1>&2 |
1700
e2f91e0acbb8
hgmerge: add cleanup functions
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1699
diff
changeset
|
129 |
failure |
1434
696851b1bba9
Fix use of diff(1) triggered by set -e.
levon@movementarian.org
parents:
839
diff
changeset
|
130 |
fi |
240 | 131 |
fi |
132 |
||
1664
4338e33c973b
Safer version of FileMerge merge
Brendan Cully <brendan@kublai.com>
parents:
1647
diff
changeset
|
133 |
# on MacOS X try FileMerge.app, shipped with Apple's developer tools |
1699
83e8cd97b9f9
hgmerge: add and use more tool variables
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1664
diff
changeset
|
134 |
if [ -n "$FILEMERGE" ]; then |
1701
4ba8fe499df2
hgmerge: various cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1700
diff
changeset
|
135 |
cp "$BACKUP" "$LOCAL" |
4ba8fe499df2
hgmerge: various cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1700
diff
changeset
|
136 |
cp "$BACKUP" "$CHGTEST" |
1664
4338e33c973b
Safer version of FileMerge merge
Brendan Cully <brendan@kublai.com>
parents:
1647
diff
changeset
|
137 |
# filemerge prefers the right by default |
1701
4ba8fe499df2
hgmerge: various cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1700
diff
changeset
|
138 |
$FILEMERGE -left "$OTHER" -right "$LOCAL" -ancestor "$BASE" -merge "$LOCAL" |
4ba8fe499df2
hgmerge: various cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1700
diff
changeset
|
139 |
[ $? -ne 0 ] && echo "FileMerge failed to launch" && failure |
4855
e4480f2b61e9
Check for conflict markers in hgmerge (issue471)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2051
diff
changeset
|
140 |
$TEST "$LOCAL" -nt "$CHGTEST" && conflicts_or_success || ask_if_merged |
1647
64a1169c927d
Use of opendiff as merge program on MacOS X
Christian Ebert <blacktrash@gmx.net>
parents:
1434
diff
changeset
|
141 |
fi |
64a1169c927d
Use of opendiff as merge program on MacOS X
Christian Ebert <blacktrash@gmx.net>
parents:
1434
diff
changeset
|
142 |
|
303
15a9e55e7ea5
Check if $DISPLAY is set before using tkdiff or kdiff3.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
280
diff
changeset
|
143 |
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
|
144 |
# try using kdiff3, which is fairly nice |
1699
83e8cd97b9f9
hgmerge: add and use more tool variables
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1664
diff
changeset
|
145 |
if [ -n "$KDIFF3" ]; then |
1798
d610fe0e6893
hgmerge: do not use file with markers in tools merging themselves
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1797
diff
changeset
|
146 |
$KDIFF3 --auto "$BASE" "$BACKUP" "$OTHER" -o "$LOCAL" || failure |
4855
e4480f2b61e9
Check for conflict markers in hgmerge (issue471)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2051
diff
changeset
|
147 |
conflicts_or_success |
240 | 148 |
fi |
149 |
||
303
15a9e55e7ea5
Check if $DISPLAY is set before using tkdiff or kdiff3.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
280
diff
changeset
|
150 |
# try using tkdiff, which is a bit less sophisticated |
1699
83e8cd97b9f9
hgmerge: add and use more tool variables
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1664
diff
changeset
|
151 |
if [ -n "$TKDIFF" ]; then |
1798
d610fe0e6893
hgmerge: do not use file with markers in tools merging themselves
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1797
diff
changeset
|
152 |
$TKDIFF "$BACKUP" "$OTHER" -a "$BASE" -o "$LOCAL" || failure |
4855
e4480f2b61e9
Check for conflict markers in hgmerge (issue471)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2051
diff
changeset
|
153 |
conflicts_or_success |
240 | 154 |
fi |
1774
ac7b91bcbd8d
hgmerge: add meld support
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1773
diff
changeset
|
155 |
|
ac7b91bcbd8d
hgmerge: add meld support
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1773
diff
changeset
|
156 |
if [ -n "$MELD" ]; then |
ac7b91bcbd8d
hgmerge: add meld support
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1773
diff
changeset
|
157 |
cp "$BACKUP" "$CHGTEST" |
ac7b91bcbd8d
hgmerge: add meld support
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1773
diff
changeset
|
158 |
# protect our feet - meld allows us to save to the left file |
ac7b91bcbd8d
hgmerge: add meld support
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1773
diff
changeset
|
159 |
cp "$BACKUP" "$LOCAL.tmp.$RAND" |
ac7b91bcbd8d
hgmerge: add meld support
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1773
diff
changeset
|
160 |
# Meld doesn't have automatic merging, so to reduce intervention |
ac7b91bcbd8d
hgmerge: add meld support
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1773
diff
changeset
|
161 |
# use the file with conflicts |
ac7b91bcbd8d
hgmerge: add meld support
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1773
diff
changeset
|
162 |
$MELD "$LOCAL.tmp.$RAND" "$LOCAL" "$OTHER" || failure |
ac7b91bcbd8d
hgmerge: add meld support
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1773
diff
changeset
|
163 |
# Also it doesn't return good error code |
4855
e4480f2b61e9
Check for conflict markers in hgmerge (issue471)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2051
diff
changeset
|
164 |
$TEST "$LOCAL" -nt "$CHGTEST" && conflicts_or_success || ask_if_merged |
1774
ac7b91bcbd8d
hgmerge: add meld support
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1773
diff
changeset
|
165 |
fi |
240 | 166 |
fi |
167 |
||
168 |
# Attempt to do a merge with $EDITOR |
|
1772
b1a7fd503a29
hgmerge: logic changes
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1771
diff
changeset
|
169 |
if [ -n "$MERGE" -o -n "$DIFF3" ]; then |
242 | 170 |
echo "conflicts detected in $LOCAL" |
1772
b1a7fd503a29
hgmerge: logic changes
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1771
diff
changeset
|
171 |
cp "$BACKUP" "$CHGTEST" |
5172
f53d97d651f4
Use smerge minor mode in emacs to resolve conflicts.
Sascha Wilde <wilde@sha-bang.de>
parents:
4855
diff
changeset
|
172 |
case "$EDITOR" in |
f53d97d651f4
Use smerge minor mode in emacs to resolve conflicts.
Sascha Wilde <wilde@sha-bang.de>
parents:
4855
diff
changeset
|
173 |
"emacs") |
f53d97d651f4
Use smerge minor mode in emacs to resolve conflicts.
Sascha Wilde <wilde@sha-bang.de>
parents:
4855
diff
changeset
|
174 |
$EDITOR "$LOCAL" --eval '(condition-case nil (smerge-mode 1) (error nil))' || failure |
f53d97d651f4
Use smerge minor mode in emacs to resolve conflicts.
Sascha Wilde <wilde@sha-bang.de>
parents:
4855
diff
changeset
|
175 |
;; |
f53d97d651f4
Use smerge minor mode in emacs to resolve conflicts.
Sascha Wilde <wilde@sha-bang.de>
parents:
4855
diff
changeset
|
176 |
*) |
f53d97d651f4
Use smerge minor mode in emacs to resolve conflicts.
Sascha Wilde <wilde@sha-bang.de>
parents:
4855
diff
changeset
|
177 |
$EDITOR "$LOCAL" || failure |
f53d97d651f4
Use smerge minor mode in emacs to resolve conflicts.
Sascha Wilde <wilde@sha-bang.de>
parents:
4855
diff
changeset
|
178 |
;; |
f53d97d651f4
Use smerge minor mode in emacs to resolve conflicts.
Sascha Wilde <wilde@sha-bang.de>
parents:
4855
diff
changeset
|
179 |
esac |
1772
b1a7fd503a29
hgmerge: logic changes
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1771
diff
changeset
|
180 |
# Some editors do not return meaningful error codes |
b1a7fd503a29
hgmerge: logic changes
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1771
diff
changeset
|
181 |
# Do not take any chances |
4855
e4480f2b61e9
Check for conflict markers in hgmerge (issue471)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2051
diff
changeset
|
182 |
$TEST "$LOCAL" -nt "$CHGTEST" && conflicts_or_success || ask_if_merged |
240 | 183 |
fi |
184 |
||
185 |
# attempt to manually merge with diff and patch |
|
1434
696851b1bba9
Fix use of diff(1) triggered by set -e.
levon@movementarian.org
parents:
839
diff
changeset
|
186 |
if [ -n "$DIFF" -a -n "$PATCH" ]; then |
795
cd0ad12d9e42
Remove usage of ${par:-word}, which and mktemp. Quote filenames.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
547
diff
changeset
|
187 |
|
829
764b0350acb8
Shortened hgmerge a little bit.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
828
diff
changeset
|
188 |
(umask 077 && mkdir "$HGTMP") || { |
1770
4eea6a747c27
hgmerge: fix diff+patch detection; cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1701
diff
changeset
|
189 |
echo "Could not create temporary directory $HGTMP" 1>&2 |
4eea6a747c27
hgmerge: fix diff+patch detection; cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1701
diff
changeset
|
190 |
failure |
829
764b0350acb8
Shortened hgmerge a little bit.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
828
diff
changeset
|
191 |
} |
795
cd0ad12d9e42
Remove usage of ${par:-word}, which and mktemp. Quote filenames.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
547
diff
changeset
|
192 |
|
1434
696851b1bba9
Fix use of diff(1) triggered by set -e.
levon@movementarian.org
parents:
839
diff
changeset
|
193 |
$DIFF -u "$BASE" "$OTHER" > "$HGTMP/diff" || : |
696851b1bba9
Fix use of diff(1) triggered by set -e.
levon@movementarian.org
parents:
839
diff
changeset
|
194 |
if $PATCH "$LOCAL" < "$HGTMP/diff"; then |
1770
4eea6a747c27
hgmerge: fix diff+patch detection; cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1701
diff
changeset
|
195 |
success |
829
764b0350acb8
Shortened hgmerge a little bit.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
828
diff
changeset
|
196 |
else |
1770
4eea6a747c27
hgmerge: fix diff+patch detection; cleanups
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1701
diff
changeset
|
197 |
# If rejects are empty after using the editor, merge was ok |
1772
b1a7fd503a29
hgmerge: logic changes
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1771
diff
changeset
|
198 |
$EDITOR "$LOCAL" "$LOCAL.rej" || failure |
2051
6a03cff2b0f5
Try to use /usr/bin/test or /bin/test to work around missing features.
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1885
diff
changeset
|
199 |
$TEST -s "$LOCAL.rej" || success |
240 | 200 |
fi |
1700
e2f91e0acbb8
hgmerge: add cleanup functions
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1699
diff
changeset
|
201 |
failure |
240 | 202 |
fi |
203 |
||
1773
aae93c3bffb4
hgmerge: improve "apps not found" message
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1772
diff
changeset
|
204 |
echo |
aae93c3bffb4
hgmerge: improve "apps not found" message
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1772
diff
changeset
|
205 |
echo "hgmerge: unable to find any merge utility!" |
aae93c3bffb4
hgmerge: improve "apps not found" message
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1772
diff
changeset
|
206 |
echo "supported programs:" |
1774
ac7b91bcbd8d
hgmerge: add meld support
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1773
diff
changeset
|
207 |
echo "merge, FileMerge, tkdiff, kdiff3, meld, diff+patch" |
1773
aae93c3bffb4
hgmerge: improve "apps not found" message
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1772
diff
changeset
|
208 |
echo |
1700
e2f91e0acbb8
hgmerge: add cleanup functions
Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
parents:
1699
diff
changeset
|
209 |
failure |