{"thread":{"id":"24766","subject":"[BUG] merge into unborn branch resets index+WT even if populated","startedAt":"2010-08-17T07:45:31Z","lastAt":"2010-08-22T21:06:29Z","messageCount":2,"participants":["Thomas Rast"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"148258","messageId":"201008170945.31850.trast@student.ethz.ch","threadId":"24766","inReplyTo":null,"subject":"[BUG] merge into unborn branch resets index+WT even if populated","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2010-08-17T07:45:31Z","receivedAt":"2010-08-17T07:45:31Z","isPatch":false,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Hi,\n\nI'm posting this on behalf of Dscho who reported it on IRC, but\napparently doesn't have the time for email.\n\nIf you run the following sequence of commands:\n\n  git init\n  echo foo > somefile\n  git add somefile\n  git pull elsewhere master\n\n(where 'elsewhere' is any repo having a master branch) the \"merge into\nunborn branch\" logic silently nukes the index AND worktree copy of\n\"somefile\", thereby losing it.  The same works with fetch+merge, so\nit's not pull's fault.\n\n-- \nThomas Rast\ntrast@{inf,student}.ethz.ch\n"},{"id":"148718","messageId":"49ac8bd95d88739f2fd9b37619ecf1c471b3a04f.1282510960.git.trast@student.ethz.ch","threadId":"24766","inReplyTo":"201008170945.31850.trast@student.ethz.ch","subject":"[PATCH] Exhibit merge bug that clobbers index&WT","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2010-08-22T21:06:29Z","receivedAt":"2010-08-22T21:06:29Z","isPatch":true,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Running git-merge on an unborn branch is supposed to do an index-level\nmerge with the other side, and then update the branch name there.  In\nthe common case where the index was empty at the start, this makes\n'git pull otherrepo branch' a convenient way to populate the history\nafter 'git init'.\n\nHowever, if the index was *not* empty, git-merge silently discards\n*both index and worktree* copies of all files that were tracked,\nleading to data loss.  Exhibit this bug.\n\nReported-by: Johannes Schindelin <johannes.schindelin@gmx.de>\nSigned-off-by: Thomas Rast <trast@student.ethz.ch>\n---\n\nHere's a less lazy approach at a bug report.\n\nI'm not too happy that noone went for a fix though; this is a real\ndata loss scenario and from his complaints on IRC, Dscho actually hit\nit and had to reconstruct from the blobs.\n\n\n t/t7607-merge-overwrite.sh |   16 ++++++++++++++++\n 1 files changed, 16 insertions(+), 0 deletions(-)\n\ndiff --git a/t/t7607-merge-overwrite.sh b/t/t7607-merge-overwrite.sh\nindex d82349a..ff08ebf 100755\n--- a/t/t7607-merge-overwrite.sh\n+++ b/t/t7607-merge-overwrite.sh\n@@ -84,4 +84,20 @@ test_expect_success 'will not overwrite removed file with staged changes' '\n \ttest_cmp important c1.c\n '\n \n+test_expect_success 'set up unborn branch and content' '\n+\tgit symbolic-ref HEAD refs/heads/unborn &&\n+\trm -f .git/index &&\n+\techo foo > tracked-file &&\n+\tgit add tracked-file &&\n+\techo bar > untracked-file\n+'\n+\n+test_expect_failure 'will not clobber WT/index when merging into unborn' '\n+\tgit merge master &&\n+\tgrep foo tracked-file &&\n+\tgit show :tracked-file >expect &&\n+\tgrep foo expect &&\n+\tgrep bar untracked-file\n+'\n+\n test_done\n-- \n1.7.2.2.479.g07acc\n"}]}