git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [BUG] merge into unborn branch resets index+WT even if populated
@ 2010-08-17  7:45 Thomas Rast
  2010-08-22 21:06 ` [PATCH] Exhibit merge bug that clobbers index&WT Thomas Rast
  0 siblings, 1 reply; 2+ messages in thread
From: Thomas Rast @ 2010-08-17  7:45 UTC (permalink / raw)
  To: git; +Cc: Johannes Schindelin

Hi,

I'm posting this on behalf of Dscho who reported it on IRC, but
apparently doesn't have the time for email.

If you run the following sequence of commands:

  git init
  echo foo > somefile
  git add somefile
  git pull elsewhere master

(where 'elsewhere' is any repo having a master branch) the "merge into
unborn branch" logic silently nukes the index AND worktree copy of
"somefile", thereby losing it.  The same works with fetch+merge, so
it's not pull's fault.

-- 
Thomas Rast
trast@{inf,student}.ethz.ch

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH] Exhibit merge bug that clobbers index&WT
  2010-08-17  7:45 [BUG] merge into unborn branch resets index+WT even if populated Thomas Rast
@ 2010-08-22 21:06 ` Thomas Rast
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Rast @ 2010-08-22 21:06 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Johannes Schindelin

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-08-22 21:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-17  7:45 [BUG] merge into unborn branch resets index+WT even if populated Thomas Rast
2010-08-22 21:06 ` [PATCH] Exhibit merge bug that clobbers index&WT Thomas Rast

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).