mergetool: honor tempfile configuration when resolving delete conflicts

Teach resolve_deleted_merge() to honor the mergetool.keepBackup and mergetool.keepTemporaries configuration knobs. This ensures that the worktree is kept pristine when resolving deletion conflicts with the variables both set to false. Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

David Aguilar committed Mar 9, 2016 at 23:13 UTC a2986045e3da24c850da03eaf2f2e2a56f8d4fff
2 files changed +35 -1
git-mergetool.sh
+10 -1
@@ -126,7 +126,12 @@ resolve_deleted_merge () {
126 case "$ans" in
127 [mMcC]*)
128 git add -- "$MERGED"
129 - cleanup_temp_files --save-backup
129 + if test "$merge_keep_backup" = "true"
130 + then
131 + cleanup_temp_files --save-backup
132 + else
133 + cleanup_temp_files
134 + fi
135 return 0
136 ;;
137 [dD]*)
@@ -135,6 +140,10 @@ resolve_deleted_merge () {
140 return 0
141 ;;
142 [aA]*)
143 + if test "$merge_keep_temporaries" = "false"
144 + then
145 + cleanup_temp_files
146 + fi
147 return 1
148 ;;
149 esac
t/t7610-mergetool.sh
+25
@@ -279,6 +279,31 @@ test_expect_success 'mergetool produces no errors when keepBackup is used' '
279 : >expect &&
280 echo d | git mergetool a/a/file.txt 2>actual &&
281 test_cmp expect actual &&
282 + ! test -d a &&
283 + git reset --hard HEAD
284 +'
285 +
286 +test_expect_success 'mergetool honors tempfile config for deleted files' '
287 + test_config mergetool.keepTemporaries false &&
288 + test_must_fail git merge move-to-b &&
289 + echo d | git mergetool a/a/file.txt &&
290 + ! test -d a &&
291 + git reset --hard HEAD
292 +'
293 +
294 +test_expect_success 'mergetool keeps tempfiles when aborting delete/delete' '
295 + test_config mergetool.keepTemporaries true &&
296 + test_must_fail git merge move-to-b &&
297 + ! (echo a; echo n) | git mergetool a/a/file.txt &&
298 + test -d a/a &&
299 + cat >expect <<-\EOF &&
300 + file_BASE_.txt
301 + file_LOCAL_.txt
302 + file_REMOTE_.txt
303 + EOF
304 + ls -1 a/a | sed -e "s/[0-9]*//g" >actual &&
305 + test_cmp expect actual &&
306 + git clean -fdx &&
307 git reset --hard HEAD
308 '
309