Safer version of FileMerge merge
authorBrendan Cully <brendan@kublai.com>
Mon, 30 Jan 2006 12:02:12 +1300
changeset 1664 4338e33c973b
parent 1663 d529cdc0a3ee
child 1665 3a56574f329a
Safer version of FileMerge merge
hgmerge
--- a/hgmerge	Mon Jan 30 12:02:06 2006 +1300
+++ b/hgmerge	Mon Jan 30 12:02:12 2006 +1300
@@ -44,14 +44,37 @@
     cp "$LOCAL.orig" "$LOCAL"
 fi
 
-# on MacOS X try opendiff
-# (uses FileMerge.app, shipped with Apple's developer tools)
-if type opendiff > /dev/null 2>&1; then
-    opendiff "$LOCAL.orig" "$OTHER" -ancestor "$BASE" -merge "$LOCAL" || exit 1
-    # prevent $OTHER from being removed too early
-    # can surely be done in a more elegant way
-    sleep 1
-    exit 0
+# on MacOS X try FileMerge.app, shipped with Apple's developer tools
+# TODO: make proper temp files. foo.orig and foo.link are dangerous
+FILEMERGE='/Developer/Applications/Utilities/FileMerge.app/Contents/MacOS/FileMerge'
+if type "$FILEMERGE" > /dev/null 2>&1; then
+    cp "$LOCAL.orig" "$LOCAL"
+    ln "$LOCAL" "$LOCAL.link"
+    # filemerge prefers the right by default
+    if ! "$FILEMERGE" -left "$OTHER" -right "$LOCAL" -ancestor "$BASE" -merge "$LOCAL"
+    then
+        echo "FileMerge failed to launch"
+        exit 1
+    fi
+    if ! test "$LOCAL" -ef "$LOCAL.link"
+    then
+        rm "$LOCAL.orig" "$LOCAL.link"
+        exit 0
+    else
+        rm "$LOCAL.link"
+        echo "$LOCAL is unchanged. Was the merge successful?"
+        select answer in yes no
+        do
+            if test "$answer" == "yes"
+            then
+                rm "$LOCAL.orig"
+                exit 0
+            else
+                exit 1
+            fi
+        done
+        exit 1
+    fi
 fi
 
 if [ -n "$DISPLAY" ]; then