From: Jonathan Nieder <jrnieder@gmail.com>
To: Stefan Beller <stefanbeller@gmail.com>
Cc: gitster@pobox.com, Johannes.Schindelin@gmx.de,
barkalow@iabervon.org, git@vger.kernel.org
Subject: [PATCH 3/3] checkout -m: attempt merge when deletion of path was staged
Date: Tue, 12 Aug 2014 17:03:18 -0700 [thread overview]
Message-ID: <20140813000317.GG24621@google.com> (raw)
In-Reply-To: <20140812235731.GD24621@google.com>
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 motivating case hasn't been tested.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
This is the most iffy of the three patches, mostly because I was too
lazy to write a test. I believe it's safe as-is nonetheless.
Thanks for reading.
unpack-trees.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/unpack-trees.c b/unpack-trees.c
index 187b15b..6c45af7 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1178,7 +1178,8 @@ return_failed:
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)
@@ -1633,7 +1634,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);
}
/*
@@ -1641,7 +1642,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 */
@@ -1770,7 +1771,7 @@ int twoway_merge(const struct cache_entry * const *src,
else
return merged_entry(newtree, current, o);
}
- return o->gently ? -1 : reject_merge(current, o);
+ return reject_merge(current, o);
} else if ((!oldtree && !newtree) || /* 4 and 5 */
(!oldtree && newtree &&
same(current, newtree)) || /* 6 and 7 */
@@ -1788,7 +1789,7 @@ int twoway_merge(const struct cache_entry * const *src,
/* 20 or 21 */
return merged_entry(newtree, current, o);
} else
- return o->gently ? -1 : reject_merge(current, o);
+ return reject_merge(current, o);
}
else if (newtree) {
if (oldtree && !o->initial_checkout) {
--
next prev parent reply other threads:[~2014-08-13 0:03 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-11 19:44 [PATCH] unpack-tree.c: remove dead code Stefan Beller
2014-08-12 18:13 ` Junio C Hamano
2014-08-12 21:15 ` Stefan Beller
2014-08-12 22:24 ` Junio C Hamano
2014-08-12 23:57 ` [PATCH 0/3] " Jonathan Nieder
2014-08-12 23:59 ` [PATCH 1/3] unpack-trees: simplify 'all other failures' case Jonathan Nieder
2014-08-13 0:00 ` [PATCH 2/3] unpack-trees: use 'cuddled' style for if-else cascade Jonathan Nieder
2014-08-13 14:52 ` Ronnie Sahlberg
2014-08-13 0:03 ` Jonathan Nieder [this message]
2014-08-13 0:38 ` [PATCH 3/3] checkout -m: attempt merge when deletion of path was staged Junio C Hamano
2014-08-13 17:48 ` Junio C Hamano
2014-08-13 18:59 ` Junio C Hamano
2014-08-13 19:30 ` Johannes Sixt
2014-08-13 20:02 ` Junio C Hamano
2014-08-13 6:41 ` [PATCH 0/3] Re: [PATCH] unpack-tree.c: remove dead code Stefan Beller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140813000317.GG24621@google.com \
--to=jrnieder@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=barkalow@iabervon.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=stefanbeller@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).