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

[PATCH] Exhibit merge bug that clobbers index&WT

From
Thomas Rast <trast@student.ethz.ch>
Date
Aug 22, 2010, 21:06 UTC
Message-ID
<49ac8bd95d88739f2fd9b37619ecf1c471b3a04f.1282510960.git.trast@student.ethz.ch>
In-Reply-To
<201008170945.31850.trast@student.ethz.ch>

Running git-merge on an unborn branch is supposed to do an index-level merge with the other side, and then update the branch name there. In the common case where the index was empty at the start, this makes 'git pull otherrepo branch' a convenient way to populate the history after 'git init'.

However, if the index was *not* empty, git-merge silently discards *both index and worktree* copies of all files that were tracked, leading to data loss. Exhibit this bug.

Reported-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
Here's a less lazy approach at a bug report.

I'm not too happy that noone went for a fix though; this is a real data loss scenario and from his complaints on IRC, Dscho actually hit it and had to reconstruct from the blobs.

 t/t7607-merge-overwrite.sh |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/t/t7607-merge-overwrite.sh b/t/t7607-merge-overwrite.sh
index d82349a..ff08ebf 100755
--- a/t/t7607-merge-overwrite.sh
+++ b/t/t7607-merge-overwrite.sh
@@ -84,4 +84,20 @@ test_expect_success 'will not overwrite removed file with staged changes' '
 	test_cmp important c1.c
 '
 
+test_expect_success 'set up unborn branch and content' '
+	git symbolic-ref HEAD refs/heads/unborn &&
+	rm -f .git/index &&
+	echo foo > tracked-file &&
+	git add tracked-file &&
+	echo bar > untracked-file
+'
+
+test_expect_failure 'will not clobber WT/index when merging into unborn' '
+	git merge master &&
+	grep foo tracked-file &&
+	git show :tracked-file >expect &&
+	grep foo expect &&
+	grep bar untracked-file
+'
+
 test_done
-- 
1.7.2.2.479.g07acc
Previous: Thomas Rast
Message 2 of 2 in “[BUG] merge into unborn branch resets index+WT even if populated”
  1. Thomas RastAug 17, 2010
  2. Exhibit merge bug that clobbers index&WTThomas Rast, Aug 22, 2010

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.