Skip to content

Commit a298604

Browse files
davvidgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent faaab8d commit a298604

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

git-mergetool.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,12 @@ resolve_deleted_merge () {
126126
case "$ans" in
127127
[mMcC]*)
128128
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
130135
return 0
131136
;;
132137
[dD]*)
@@ -135,6 +140,10 @@ resolve_deleted_merge () {
135140
return 0
136141
;;
137142
[aA]*)
143+
if test "$merge_keep_temporaries" = "false"
144+
then
145+
cleanup_temp_files
146+
fi
138147
return 1
139148
;;
140149
esac

t/t7610-mergetool.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,31 @@ test_expect_success 'mergetool produces no errors when keepBackup is used' '
279279
: >expect &&
280280
echo d | git mergetool a/a/file.txt 2>actual &&
281281
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 &&
282307
git reset --hard HEAD
283308
'
284309

0 commit comments

Comments
 (0)