Skip to content

Commit

Permalink
mergetool: Don't keep temporary merge files unless told to
Browse files Browse the repository at this point in the history
This changes git mergetool to remove the temporary files used to invoke
the merge tool even if it returns non-zero.

This also adds a configuration option (mergetool.keepTemporaries) to
retain the previous behaviour if desired.

Signed-off-by: Charles Bailey <charles@hashpling.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Charles Bailey authored and Junio C Hamano committed Dec 13, 2008
1 parent b0169d8 commit 162eba8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Documentation/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,13 @@ mergetool.keepBackup::
is set to `false` then this file is not preserved. Defaults to
`true` (i.e. keep the backup files).

mergetool.keepTemporaries::
When invoking a custom merge tool, git uses a set of temporary
files to pass to the tool. If the tool returns an error and this
variable is set to `true`, then these temporary files will be
preserved, otherwise they will be removed after the tool has
exited. Defaults to `false`.

mergetool.prompt::
Prompt before each invocation of the merge resolution program.

Expand Down
6 changes: 6 additions & 0 deletions git-mergetool.sh
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ merge_file () {
if test "$status" -ne 0; then
echo "merge of $MERGED failed" 1>&2
mv -- "$BACKUP" "$MERGED"

if test "$merge_keep_temporaries" = "false"; then
cleanup_temp_files
fi

return 1
fi

Expand Down Expand Up @@ -415,6 +420,7 @@ else
init_merge_tool_path "$merge_tool"

merge_keep_backup="$(git config --bool merge.keepBackup || echo true)"
merge_keep_temporaries="$(git config --bool mergetool.keepTemporaries || echo false)"

if test -z "$merge_tool_cmd" && ! type "$merge_tool_path" > /dev/null 2>&1; then
echo "The merge tool $merge_tool is not available as '$merge_tool_path'"
Expand Down

0 comments on commit 162eba8

Please sign in to comment.