mirror of
https://github.com/git/git
synced 2024-08-24 18:26:02 +00:00
Merge branch 'jn/unpack-trees-checkout-m-carry-deletion'
"git checkout -m" did not switch to another branch while carrying the local changes forward when a path was deleted from the index. * jn/unpack-trees-checkout-m-carry-deletion: checkout -m: attempt merge when deletion of path was staged unpack-trees: use 'cuddled' style for if-else cascade unpack-trees: simplify 'all other failures' case
This commit is contained in:
commit
f28763d756
|
@ -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 &&
|
||||
|
|
|
@ -1176,7 +1176,8 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
|
|||
static int reject_merge(const struct cache_entry *ce,
|
||||
struct unpack_trees_options *o)
|
||||
{
|
||||
return add_rejected_path(o, ERROR_WOULD_OVERWRITE, ce->name);
|
||||
return o->gently ? -1 :
|
||||
add_rejected_path(o, ERROR_WOULD_OVERWRITE, ce->name);
|
||||
}
|
||||
|
||||
static int same(const struct cache_entry *a, const struct cache_entry *b)
|
||||
|
@ -1631,7 +1632,7 @@ int threeway_merge(const struct cache_entry * const *stages,
|
|||
/* #14, #14ALT, #2ALT */
|
||||
if (remote && !df_conflict_head && head_match && !remote_match) {
|
||||
if (index && !same(index, remote) && !same(index, head))
|
||||
return o->gently ? -1 : reject_merge(index, o);
|
||||
return reject_merge(index, o);
|
||||
return merged_entry(remote, index, o);
|
||||
}
|
||||
/*
|
||||
|
@ -1639,7 +1640,7 @@ int threeway_merge(const struct cache_entry * const *stages,
|
|||
* make sure that it matches head.
|
||||
*/
|
||||
if (index && !same(index, head))
|
||||
return o->gently ? -1 : reject_merge(index, o);
|
||||
return reject_merge(index, o);
|
||||
|
||||
if (head) {
|
||||
/* #5ALT, #15 */
|
||||
|
@ -1768,9 +1769,8 @@ int twoway_merge(const struct cache_entry * const *src,
|
|||
else
|
||||
return merged_entry(newtree, current, o);
|
||||
}
|
||||
return o->gently ? -1 : reject_merge(current, o);
|
||||
}
|
||||
else if ((!oldtree && !newtree) || /* 4 and 5 */
|
||||
return reject_merge(current, o);
|
||||
} else if ((!oldtree && !newtree) || /* 4 and 5 */
|
||||
(!oldtree && newtree &&
|
||||
same(current, newtree)) || /* 6 and 7 */
|
||||
(oldtree && newtree &&
|
||||
|
@ -1779,26 +1779,15 @@ int twoway_merge(const struct cache_entry * const *src,
|
|||
!same(oldtree, newtree) && /* 18 and 19 */
|
||||
same(current, newtree))) {
|
||||
return keep_entry(current, o);
|
||||
}
|
||||
else if (oldtree && !newtree && same(current, oldtree)) {
|
||||
} else if (oldtree && !newtree && same(current, oldtree)) {
|
||||
/* 10 or 11 */
|
||||
return deleted_entry(oldtree, current, o);
|
||||
}
|
||||
else if (oldtree && newtree &&
|
||||
} else if (oldtree && newtree &&
|
||||
same(current, oldtree) && !same(current, newtree)) {
|
||||
/* 20 or 21 */
|
||||
return merged_entry(newtree, current, o);
|
||||
}
|
||||
else {
|
||||
/* all other failures */
|
||||
if (oldtree)
|
||||
return o->gently ? -1 : reject_merge(oldtree, o);
|
||||
if (current)
|
||||
return o->gently ? -1 : reject_merge(current, o);
|
||||
if (newtree)
|
||||
return o->gently ? -1 : reject_merge(newtree, o);
|
||||
return -1;
|
||||
}
|
||||
} else
|
||||
return reject_merge(current, o);
|
||||
}
|
||||
else if (newtree) {
|
||||
if (oldtree && !o->initial_checkout) {
|
||||
|
|
Loading…
Reference in a new issue