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

[PATCH 4/7] rerere: do not record failed conflict resolution data

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
Sep 17, 2026, 17:52 UTC
Message-ID
<bd9e06e46c6debb5a8fc8f1d3821250ca110d5ef.1789667556.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.2231.git.1789667556.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>

`rerere` can mark a conflict variant as resolved even when writing its preimage or postimage fails. A later invocation may then replay incomplete data from the cache, turning a local filesystem failure into an incorrect working-tree change.

629716d256a7 (rerere: do use multiple variants, 2015-07-30) introduced the code paths without checks for those I/O results. Treat such failures as failures, report them, and leave the rerere status unchanged unless the corresponding data was recorded successfully.

The defect has been latent since 2015. Git for Windows' Coverity run only reported it after merging v2.56.0-rc0, for reasons that could not be figured out in a reasonable amount of time.

Assisted-by: GPT-5.6 Luna
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 rerere.c | 30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)
diff --git a/rerere.c b/rerere.c
index 1c3745d9e3..45bbe6ab2c 100644
--- a/rerere.c
+++ b/rerere.c
@@ -476,8 +476,11 @@ static int handle_file(struct index_state *istate,
 			unlink_or_warn(output);
 		return error(_("could not parse conflict hunks in '%s'"), path);
 	}
-	if (io.io.wrerror)
+	if (io.io.wrerror) {
+		if (output)
+			unlink_or_warn(output);
 		return -1;
+	}
 	return has_conflicts;
 }
 
@@ -729,8 +732,25 @@ static void do_rerere_one_path(struct index_state *istate,
 
 	/* Has the user resolved it already? */
 	if (variant >= 0) {
-		if (!handle_file(istate, path, NULL, NULL)) {
-			copy_file(the_repository, rerere_path(&buf, id, "postimage"), path, 0666);
+		int ret = handle_file(istate, path, NULL, NULL);
+
+		if (ret < 0)
+			goto out;
+		if (!ret) {
+			const int had_postimage =
+				id->collection->status[variant] & RR_HAS_POSTIMAGE;
+			const char *postimage =
+				rerere_path(&buf, id, "postimage");
+
+			if (copy_file(the_repository,
+				      postimage,
+				      path, 0666)) {
+				if (!had_postimage)
+					unlink_or_warn(postimage);
+				error_errno(_("could not copy resolution for '%s'"),
+					    path);
+				goto out;
+			}
 			id->collection->status[variant] |= RR_HAS_POSTIMAGE;
 			fprintf_ln(stderr, _("Recorded resolution for '%s'."), path);
 			free_rerere_id(rr_item);
@@ -778,7 +798,9 @@ static void do_rerere_one_path(struct index_state *istate,
 	assign_variant(id);
 
 	variant = id->variant;
-	handle_file(istate, path, NULL, rerere_path(&buf, id, "preimage"));
+	if (handle_file(istate, path, NULL,
+			rerere_path(&buf, id, "preimage")) < 0)
+		goto out;
 	if (id->collection->status[variant] & RR_HAS_POSTIMAGE) {
 		const char *path = rerere_path(&buf, id, "postimage");
 		if (unlink(path))
-- 
gitgitgadget
Previous: Johannes Schindelin via GitGitGadgetNext: Junio C Hamano
Message 8 of 12 in “Fix issues pointed out in Git for Windows by Coverity after merging v2.56.0-rc0”
  1. 0/7 Fix issues pointed out in Git for Windows by Coverity after merging v2.56.0-rc0Johannes Schindelin via GitGitGadget, Sep 17, 2026
  2. 1/7 wrapper: guard writev_in_full() against signed overflowJohannes Schindelin via GitGitGadget, Sep 17, 2026
  3. 2/7 gpg-interface: make signature-prefix matching length-awareJohannes Schindelin via GitGitGadget, Sep 17, 2026
  4. Junio C HamanoSep 17, 2026
  5. Johannes SchindelinSep 18, 2026
  6. Junio C HamanoSep 18, 2026
  7. 3/7 midx: validate incremental MIDX pack IDsJohannes Schindelin via GitGitGadget, Sep 17, 2026
  8. 4/7 rerere: do not record failed conflict resolution dataJohannes Schindelin via GitGitGadget, Sep 17, 2026
  9. Junio C HamanoSep 17, 2026
  10. 5/7 t/unit-tests: check reftable iterator initializationJohannes Schindelin via GitGitGadget, Sep 17, 2026
  11. 6/7 oss-fuzz: handle reftable iterator initialization failuresJohannes Schindelin via GitGitGadget, Sep 17, 2026
  12. 7/7 test-read-midx: check midx_fill_entry() resultJohannes Schindelin via GitGitGadget, Sep 17, 2026

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.