hgmerge
changeset 5344 cc34be74eeec
parent 5171 f53d97d651f4
equal deleted inserted replaced
5343:26692d08c2f9 5344:cc34be74eeec
    94             n*|N*) failure;;
    94             n*|N*) failure;;
    95         esac
    95         esac
    96     done
    96     done
    97 }
    97 }
    98 
    98 
       
    99 # Check if conflict markers are present and ask if the merge was successful
       
   100 conflicts_or_success() {
       
   101     while egrep '^(<<<<<<< .*|=======|>>>>>>> .*)$' "$LOCAL" >/dev/null; do
       
   102         echo "$LOCAL contains conflict markers."
       
   103         echo "Keep this version? [y/n]"
       
   104         read answer
       
   105         case "$answer" in
       
   106             y*|Y*) success;;
       
   107             n*|N*) failure;;
       
   108         esac
       
   109     done
       
   110     success
       
   111 }
       
   112 
    99 # Clean up when interrupted
   113 # Clean up when interrupted
   100 trap "failure" 1 2 3 6 15 # HUP INT QUIT ABRT TERM
   114 trap "failure" 1 2 3 6 15 # HUP INT QUIT ABRT TERM
   101 
   115 
   102 # Back up our file (and try hard to keep the mtime unchanged)
   116 # Back up our file (and try hard to keep the mtime unchanged)
   103 mv "$LOCAL" "$BACKUP"
   117 mv "$LOCAL" "$BACKUP"
   121     cp "$BACKUP" "$LOCAL"
   135     cp "$BACKUP" "$LOCAL"
   122     cp "$BACKUP" "$CHGTEST"
   136     cp "$BACKUP" "$CHGTEST"
   123     # filemerge prefers the right by default
   137     # filemerge prefers the right by default
   124     $FILEMERGE -left "$OTHER" -right "$LOCAL" -ancestor "$BASE" -merge "$LOCAL"
   138     $FILEMERGE -left "$OTHER" -right "$LOCAL" -ancestor "$BASE" -merge "$LOCAL"
   125     [ $? -ne 0 ] && echo "FileMerge failed to launch" && failure
   139     [ $? -ne 0 ] && echo "FileMerge failed to launch" && failure
   126     $TEST "$LOCAL" -nt "$CHGTEST" && success || ask_if_merged
   140     $TEST "$LOCAL" -nt "$CHGTEST" && conflicts_or_success || ask_if_merged
   127 fi
   141 fi
   128 
   142 
   129 if [ -n "$DISPLAY" ]; then
   143 if [ -n "$DISPLAY" ]; then
   130     # try using kdiff3, which is fairly nice
   144     # try using kdiff3, which is fairly nice
   131     if [ -n "$KDIFF3" ]; then
   145     if [ -n "$KDIFF3" ]; then
   132         $KDIFF3 --auto "$BASE" "$BACKUP" "$OTHER" -o "$LOCAL" || failure
   146         $KDIFF3 --auto "$BASE" "$BACKUP" "$OTHER" -o "$LOCAL" || failure
   133         success
   147         conflicts_or_success
   134     fi
   148     fi
   135 
   149 
   136     # try using tkdiff, which is a bit less sophisticated
   150     # try using tkdiff, which is a bit less sophisticated
   137     if [ -n "$TKDIFF" ]; then
   151     if [ -n "$TKDIFF" ]; then
   138         $TKDIFF "$BACKUP" "$OTHER" -a "$BASE" -o "$LOCAL" || failure
   152         $TKDIFF "$BACKUP" "$OTHER" -a "$BASE" -o "$LOCAL" || failure
   139         success
   153         conflicts_or_success
   140     fi
   154     fi
   141 
   155 
   142     if [ -n "$MELD" ]; then
   156     if [ -n "$MELD" ]; then
   143         cp "$BACKUP" "$CHGTEST"
   157         cp "$BACKUP" "$CHGTEST"
   144         # protect our feet - meld allows us to save to the left file
   158         # protect our feet - meld allows us to save to the left file
   145         cp "$BACKUP" "$LOCAL.tmp.$RAND"
   159         cp "$BACKUP" "$LOCAL.tmp.$RAND"
   146         # Meld doesn't have automatic merging, so to reduce intervention
   160         # Meld doesn't have automatic merging, so to reduce intervention
   147         # use the file with conflicts
   161         # use the file with conflicts
   148         $MELD "$LOCAL.tmp.$RAND" "$LOCAL" "$OTHER" || failure
   162         $MELD "$LOCAL.tmp.$RAND" "$LOCAL" "$OTHER" || failure
   149         # Also it doesn't return good error code
   163         # Also it doesn't return good error code
   150         $TEST "$LOCAL" -nt "$CHGTEST" && success || ask_if_merged
   164         $TEST "$LOCAL" -nt "$CHGTEST" && conflicts_or_success || ask_if_merged
   151     fi
   165     fi
   152 fi
   166 fi
   153 
   167 
   154 # Attempt to do a merge with $EDITOR
   168 # Attempt to do a merge with $EDITOR
   155 if [ -n "$MERGE" -o -n "$DIFF3" ]; then
   169 if [ -n "$MERGE" -o -n "$DIFF3" ]; then
   156     echo "conflicts detected in $LOCAL"
   170     echo "conflicts detected in $LOCAL"
   157     cp "$BACKUP" "$CHGTEST"
   171     cp "$BACKUP" "$CHGTEST"
   158     $EDITOR "$LOCAL" || failure
   172     case "$EDITOR" in
       
   173         "emacs")
       
   174             $EDITOR "$LOCAL" --eval '(condition-case nil (smerge-mode 1) (error nil))' || failure
       
   175             ;;
       
   176         *)
       
   177             $EDITOR "$LOCAL" || failure
       
   178             ;;
       
   179     esac
   159     # Some editors do not return meaningful error codes
   180     # Some editors do not return meaningful error codes
   160     # Do not take any chances
   181     # Do not take any chances
   161     $TEST "$LOCAL" -nt "$CHGTEST" && success || ask_if_merged
   182     $TEST "$LOCAL" -nt "$CHGTEST" && conflicts_or_success || ask_if_merged
   162 fi
   183 fi
   163 
   184 
   164 # attempt to manually merge with diff and patch
   185 # attempt to manually merge with diff and patch
   165 if [ -n "$DIFF" -a -n "$PATCH" ]; then
   186 if [ -n "$DIFF" -a -n "$PATCH" ]; then
   166 
   187