summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorLibravatar Jeff King <peff@peff.net>2019-05-24 02:46:27 -0400
committerLibravatar Junio C Hamano <gitster@pobox.com>2019-05-28 10:26:36 -0700
commit7663e438c5ca5a1dbcfcb1a9cbf68480362998a2 (patch)
tree1172a731301b3d1dab0fe2eea72c241fd7a96ec3 /builtin
parentam: drop tty requirement for --interactive (diff)
downloadtgif-7663e438c5ca5a1dbcfcb1a9cbf68480362998a2.tar.xz
am: fix --interactive HEAD tree resolution
In --interactive mode, "git am --resolved" will try to generate a patch based on what is in the index, so that it can prompt "apply this patch?". To do so it needs the tree of HEAD, which it tries to get with get_oid_tree(). However, this doesn't yield a tree object; the "tree" part just means "if you must disambiguate short oids, then prefer trees" (and we do not need to disambiguate at all, since we are feeding a ref). Instead, we must parse the oid as a commit (which should always be true in a non-corrupt repository), and access its tree pointer manually. This has been broken since the conversion to C in 7ff2683253 (builtin-am: implement -i/--interactive, 2015-08-04), but there was no test coverage because of interactive-mode's insistence on having a tty. That was lifted in the previous commit, so we can now add a test for this case. Note that before this patch, the test would result in a BUG() which comes from 3506dc9445 (has_uncommitted_changes(): fall back to empty tree, 2018-07-11). But before that, we'd have simply segfaulted (and in fact this is the exact type of case the BUG() added there was trying to catch!). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/am.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/builtin/am.c b/builtin/am.c
index 9cbbd8eda8..d9199015f5 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1337,9 +1337,10 @@ static void write_index_patch(const struct am_state *state)
struct rev_info rev_info;
FILE *fp;
- if (!get_oid_tree("HEAD", &head))
- tree = lookup_tree(the_repository, &head);
- else
+ if (!get_oid("HEAD", &head)) {
+ struct commit *commit = lookup_commit_or_die(&head, "HEAD");
+ tree = get_commit_tree(commit);
+ } else
tree = lookup_tree(the_repository,
the_repository->hash_algo->empty_tree);