Skip to content

Commit 5b32708

Browse files
trastgitster
authored andcommitted
Exhibit merge bug that clobbers index&WT
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 <[email protected]> Signed-off-by: Thomas Rast <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d599e04 commit 5b32708

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

t/t7607-merge-overwrite.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,20 @@ test_expect_success 'will not overwrite removed file with staged changes' '
8484
test_cmp important c1.c
8585
'
8686

87+
test_expect_success 'set up unborn branch and content' '
88+
git symbolic-ref HEAD refs/heads/unborn &&
89+
rm -f .git/index &&
90+
echo foo > tracked-file &&
91+
git add tracked-file &&
92+
echo bar > untracked-file
93+
'
94+
95+
test_expect_failure 'will not clobber WT/index when merging into unborn' '
96+
git merge master &&
97+
grep foo tracked-file &&
98+
git show :tracked-file >expect &&
99+
grep foo expect &&
100+
grep bar untracked-file
101+
'
102+
87103
test_done

0 commit comments

Comments
 (0)