git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] mergetool: Don't keep temporary merge files unless told to

From
Charles Bailey <charles@hashpling.org>
Date
Dec 12, 2008, 21:48 UTC
Message-ID
<1229118521-22923-3-git-send-email-charles@hashpling.org>
In-Reply-To
<1229118521-22923-2-git-send-email-charles@hashpling.org>

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>
---
 Documentation/config.txt |    7 +++++++
 git-mergetool.sh         |    6 ++++++
 2 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index bc5642d..3d5a8df 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -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.
 
diff --git a/git-mergetool.sh b/git-mergetool.sh
index 5144971..f04240d 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -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
 
@@ -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'"
-- 
1.6.1.rc1.342.g83b24d
Previous: Charles BaileyNext: Jakub Narebski
Message 3 of 4 in “Updates to the previous mergetool patches”
  1. Charles BaileyDec 12, 2008
  2. 1/2 mergetool: Add prompt to continue after failing to merge a fileCharles Bailey, Dec 12, 2008
  3. 2/2 mergetool: Don't keep temporary merge files unless told toCharles Bailey, Dec 12, 2008
  4. Jakub NarebskiDec 12, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.