From 172b6428d06ff4eb0812f087a497d50b6c878fe1 Mon Sep 17 00:00:00 2001 From: Clemens Buchacher Date: Sun, 14 Nov 2010 23:07:49 +0100 Subject: do not overwrite untracked during merge from unborn branch In case HEAD does not point to a valid commit yet, merge is implemented as a hard reset. This will cause untracked files to be overwritten. Instead, assume the empty tree for HEAD and do a regular merge. An untracked file will cause the merge to abort and do nothing. If no conflicting files are present, the merge will have the same effect as a hard reset. Signed-off-by: Clemens Buchacher Signed-off-by: Junio C Hamano --- t/t7607-merge-overwrite.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 't/t7607-merge-overwrite.sh') diff --git a/t/t7607-merge-overwrite.sh b/t/t7607-merge-overwrite.sh index 49f4e1599a..8317a574ce 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 ' +cat >expect <<\EOF +error: Untracked working tree file 'c0.c' would be overwritten by merge. +fatal: read-tree failed +EOF + +test_expect_success 'will not overwrite untracked file on unborn branch' ' + git reset --hard c0 && + git rm -fr . && + git checkout --orphan new && + cp important c0.c && + test_must_fail git merge c0 2>out && + test_cmp out expect && + test_path_is_missing .git/MERGE_HEAD && + test_cmp important c0.c +' + test_done -- cgit v1.2.1