diff hgmerge @ 1772:b1a7fd503a29

hgmerge: logic changes Details: - keep automatic merge conflicts in $LOCAL - do not assume that $EDITOR returns proper error code - fix a slight mistake in diff+patch merge success detection (it could succeed if the $EDITOR failed to run)
author Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
date Tue, 21 Feb 2006 15:48:16 -0600
parents e22bbca2e82b
children aae93c3bffb4
line wrap: on
line diff
--- a/hgmerge	Tue Feb 21 15:48:12 2006 -0600
+++ b/hgmerge	Tue Feb 21 15:48:16 2006 -0600
@@ -101,7 +101,6 @@
         failure
     fi
 fi
-cp "$BACKUP" "$LOCAL"
 
 # on MacOS X try FileMerge.app, shipped with Apple's developer tools
 if [ -n "$FILEMERGE" ]; then
@@ -111,7 +110,6 @@
     $FILEMERGE -left "$OTHER" -right "$LOCAL" -ancestor "$BASE" -merge "$LOCAL"
     [ $? -ne 0 ] && echo "FileMerge failed to launch" && failure
     test "$LOCAL" -nt "$CHGTEST" && success || ask_if_merged
-    failure
 fi
 
 if [ -n "$DISPLAY" ]; then
@@ -129,24 +127,13 @@
 fi
 
 # Attempt to do a merge with $EDITOR
-if [ -n "$MERGE" ]; then
-    echo "conflicts detected in $LOCAL"
-    $MERGE "$LOCAL" "$BASE" "$OTHER" 2>/dev/null || $EDITOR "$LOCAL"
-    success
-fi
-
-if [ -n "$DIFF3" ]; then
+if [ -n "$MERGE" -o -n "$DIFF3" ]; then
     echo "conflicts detected in $LOCAL"
-    $DIFF3 -m "$BACKUP" "$BASE" "$OTHER" > "$LOCAL" || {
-        case $? in
-            1)
-                $EDITOR "$LOCAL" ;;
-            2)  echo "$DIFF3 failed! Exiting." 1>&2
-                cp "$BACKUP" "$LOCAL"
-                failure ;;
-        esac
-        success
-    }
+    cp "$BACKUP" "$CHGTEST"
+    $EDITOR "$LOCAL" || failure
+    # Some editors do not return meaningful error codes
+    # Do not take any chances
+    test "$LOCAL" -nt "$CHGTEST" && success || ask_if_merged
 fi
 
 # attempt to manually merge with diff and patch
@@ -162,7 +149,8 @@
         success
     else
         # If rejects are empty after using the editor, merge was ok
-        $EDITOR "$LOCAL" "$LOCAL.rej" && test -s "$LOCAL.rej" || success
+        $EDITOR "$LOCAL" "$LOCAL.rej" || failure
+        test -s "$LOCAL.rej" || success
     fi
     failure
 fi