Imported Upstream version 2.10.4
[platform/upstream/git.git] / git-mergetool.sh
index d20581c..bf86270 100755 (executable)
@@ -126,7 +126,12 @@ resolve_deleted_merge () {
                case "$ans" in
                [mMcC]*)
                        git add -- "$MERGED"
-                       cleanup_temp_files --save-backup
+                       if test "$merge_keep_backup" = "true"
+                       then
+                               cleanup_temp_files --save-backup
+                       else
+                               cleanup_temp_files
+                       fi
                        return 0
                        ;;
                [dD]*)
@@ -135,6 +140,10 @@ resolve_deleted_merge () {
                        return 0
                        ;;
                [aA]*)
+                       if test "$merge_keep_temporaries" = "false"
+                       then
+                               cleanup_temp_files
+                       fi
                        return 1
                        ;;
                esac
@@ -282,8 +291,14 @@ merge_file () {
                return
        fi
 
-       mv -- "$MERGED" "$BACKUP"
-       cp -- "$BACKUP" "$MERGED"
+       if test -f "$MERGED"
+       then
+               mv -- "$MERGED" "$BACKUP"
+               cp -- "$BACKUP" "$MERGED"
+       fi
+       # Create a parent directory to handle delete/delete conflicts
+       # where the base's directory no longer exists.
+       mkdir -p "$(dirname "$MERGED")"
 
        checkout_staged_file 1 "$MERGED" "$BASE"
        checkout_staged_file 2 "$MERGED" "$LOCAL"
@@ -295,7 +310,9 @@ merge_file () {
                describe_file "$local_mode" "local" "$LOCAL"
                describe_file "$remote_mode" "remote" "$REMOTE"
                resolve_deleted_merge
-               return
+               status=$?
+               rmdir -p "$(dirname "$MERGED")" 2>/dev/null
+               return $status
        fi
 
        if is_symlink "$local_mode" || is_symlink "$remote_mode"
@@ -396,7 +413,7 @@ done
 prompt_after_failed_merge () {
        while true
        do
-               printf "Continue merging other unresolved paths (y/n) ? "
+               printf "Continue merging other unresolved paths [y/n]? "
                read ans || return 1
                case "$ans" in
                [yY]*)
@@ -451,8 +468,6 @@ fi
 printf "Merging:\n"
 printf "%s\n" "$files"
 
-IFS='
-'
 rc=0
 for i in $files
 do