1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-10-28 04:49:43 +01:00

Merge branch 'pw/rebase-i-merge-segv-fix'

"git rebase -i", when a 'merge <branch>' insn in its todo list
fails, segfaulted, which has been (minimally) corrected.

* pw/rebase-i-merge-segv-fix:
  rebase -i: fix SIGSEGV when 'merge <branch>' fails
  t3430: add conflicting commit
This commit is contained in:
Junio C Hamano 2018-08-20 12:41:33 -07:00
commit 5a5c5e9565
2 changed files with 42 additions and 12 deletions

View file

@ -2610,8 +2610,13 @@ static int error_with_patch(struct commit *commit,
const char *subject, int subject_len,
struct replay_opts *opts, int exit_code, int to_amend)
{
if (make_patch(commit, opts))
return -1;
if (commit) {
if (make_patch(commit, opts))
return -1;
} else if (copy_file(rebase_path_message(),
git_path_merge_msg(the_repository), 0666))
return error(_("unable to copy '%s' to '%s'"),
git_path_merge_msg(the_repository), rebase_path_message());
if (to_amend) {
if (intend_to_amend())
@ -2626,9 +2631,18 @@ static int error_with_patch(struct commit *commit,
"\n"
" git rebase --continue\n"),
gpg_sign_opt_quoted(opts));
} else if (exit_code)
fprintf_ln(stderr, _("Could not apply %s... %.*s"),
short_commit_name(commit), subject_len, subject);
} else if (exit_code) {
if (commit)
fprintf_ln(stderr, _("Could not apply %s... %.*s"),
short_commit_name(commit), subject_len, subject);
else
/*
* We don't have the hash of the parent so
* just print the line from the todo file.
*/
fprintf_ln(stderr, _("Could not merge %.*s"),
subject_len, subject);
}
return exit_code;
}

View file

@ -13,8 +13,10 @@ Initial setup:
-- B -- (first)
/ \
A - C - D - E - H (master)
\ /
F - G (second)
\ \ /
\ F - G (second)
\
Conflicting-G
'
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-rebase.sh
@ -49,7 +51,9 @@ test_expect_success 'setup' '
git merge --no-commit G &&
test_tick &&
git commit -m H &&
git tag -m H H
git tag -m H H &&
git checkout A &&
test_commit conflicting-G G.t
'
test_expect_success 'create completely different structure' '
@ -72,7 +76,7 @@ test_expect_success 'create completely different structure' '
EOF
test_config sequence.editor \""$PWD"/replace-editor.sh\" &&
test_tick &&
git rebase -i -r A &&
git rebase -i -r A master &&
test_cmp_graph <<-\EOF
* Merge the topic branch '\''onebranch'\''
|\
@ -125,7 +129,7 @@ test_expect_success '`reset` refuses to overwrite untracked files' '
git rebase --abort
'
test_expect_success 'failed `merge` writes patch (may be rescheduled, too)' '
test_expect_success 'failed `merge -C` writes patch (may be rescheduled, too)' '
test_when_finished "test_might_fail git rebase --abort" &&
git checkout -b conflicting-merge A &&
@ -141,13 +145,25 @@ test_expect_success 'failed `merge` writes patch (may be rescheduled, too)' '
: fail because of merge conflict &&
rm G.t .git/rebase-merge/patch &&
git reset --hard &&
test_commit conflicting-G G.t not-G conflicting-G &&
git reset --hard conflicting-G &&
test_must_fail git rebase --continue &&
! grep "^merge -C .* G$" .git/rebase-merge/git-rebase-todo &&
test_path_is_file .git/rebase-merge/patch
'
SQ="'"
test_expect_success 'failed `merge <branch>` does not crash' '
test_when_finished "test_might_fail git rebase --abort" &&
git checkout conflicting-G &&
echo "merge G" >script-from-scratch &&
test_config sequence.editor \""$PWD"/replace-editor.sh\" &&
test_tick &&
test_must_fail git rebase -ir HEAD &&
! grep "^merge G$" .git/rebase-merge/git-rebase-todo &&
grep "^Merge branch ${SQ}G${SQ}$" .git/rebase-merge/message
'
test_expect_success 'with a branch tip that was cherry-picked already' '
git checkout -b already-upstream master &&
base="$(git rev-parse --verify HEAD)" &&