checkout -m: attempt merge when deletion of path was staged

twoway_merge() is missing an o->gently check in the case where a file
that needs to be modified is missing from the index but present in the
old and new trees.  As a result, in this case 'git checkout -m' errors
out instead of trying to perform a merge.

Fix it by checking o->gently.  While at it, inline the o->gently check
into reject_merge to prevent future call sites from making the same
mistake.

Noticed by code inspection.  The test for the motivating case was
added by JC.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jonathan Nieder
2014-08-12 17:03:18 -07:00
committed by Junio C Hamano
parent 6c1db1b388
commit 6a143aa2b2
2 changed files with 23 additions and 5 deletions

View File

@ -223,6 +223,23 @@ test_expect_success 'checkout --merge --conflict=diff3 <branch>' '
test_cmp two expect
'
test_expect_success 'switch to another branch while carrying a deletion' '
git checkout -f master && git reset --hard && git clean -f &&
git rm two &&
test_must_fail git checkout simple 2>errs &&
test_i18ngrep overwritten errs &&
git checkout --merge simple 2>errs &&
test_i18ngrep ! overwritten errs &&
git ls-files -u &&
test_must_fail git cat-file -t :0:two &&
test "$(git cat-file -t :1:two)" = blob &&
test "$(git cat-file -t :2:two)" = blob &&
test_must_fail git cat-file -t :3:two
'
test_expect_success 'checkout to detach HEAD (with advice declined)' '
git config advice.detachedHead false &&