mirror of
https://github.com/git/git
synced 2024-08-27 11:39:22 +00:00
![Jeff King](/assets/img/avatar_default.png)
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 in7ff2683253
(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 from3506dc9445
(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>
53 lines
1.3 KiB
Bash
Executable file
53 lines
1.3 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
test_description='am --interactive tests'
|
|
. ./test-lib.sh
|
|
|
|
test_expect_success 'set up patches to apply' '
|
|
test_commit unrelated &&
|
|
test_commit no-conflict &&
|
|
test_commit conflict-patch file patch &&
|
|
git format-patch --stdout -2 >mbox &&
|
|
|
|
git reset --hard unrelated &&
|
|
test_commit conflict-master file master base
|
|
'
|
|
|
|
# Sanity check our setup.
|
|
test_expect_success 'applying all patches generates conflict' '
|
|
test_must_fail git am mbox &&
|
|
echo resolved >file &&
|
|
git add -u &&
|
|
git am --resolved
|
|
'
|
|
|
|
test_expect_success 'interactive am can apply a single patch' '
|
|
git reset --hard base &&
|
|
# apply the first, but not the second
|
|
test_write_lines y n | git am -i mbox &&
|
|
|
|
echo no-conflict >expect &&
|
|
git log -1 --format=%s >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success 'interactive am can resolve conflict' '
|
|
git reset --hard base &&
|
|
# apply both; the second one will conflict
|
|
test_write_lines y y | test_must_fail git am -i mbox &&
|
|
echo resolved >file &&
|
|
git add -u &&
|
|
# interactive "--resolved" will ask us if we want to apply the result
|
|
echo y | git am -i --resolved &&
|
|
|
|
echo conflict-patch >expect &&
|
|
git log -1 --format=%s >actual &&
|
|
test_cmp expect actual &&
|
|
|
|
echo resolved >expect &&
|
|
git cat-file blob HEAD:file >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_done
|