Navigation Menu

Skip to content

Commit

Permalink
Merge branch 'pw/rebase-i-merge-segv-fix'
Browse files Browse the repository at this point in the history
"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
  • Loading branch information
gitster committed Aug 20, 2018
2 parents 36fd1e8 + bc9238b commit 5a5c5e9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
24 changes: 19 additions & 5 deletions sequencer.c
Expand Up @@ -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())
Expand All @@ -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;
}
Expand Down
30 changes: 23 additions & 7 deletions t/t3430-rebase-merges.sh
Expand Up @@ -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
Expand Down Expand Up @@ -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' '
Expand All @@ -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'\''
|\
Expand Down Expand Up @@ -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 &&
Expand All @@ -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)" &&
Expand Down

0 comments on commit 5a5c5e9

Please sign in to comment.