Skip to content

Commit 5a5c5e9

Browse files
committed
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
2 parents 36fd1e8 + bc9238b commit 5a5c5e9

File tree

2 files changed

+42
-12
lines changed

2 files changed

+42
-12
lines changed

sequencer.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2610,8 +2610,13 @@ static int error_with_patch(struct commit *commit,
26102610
const char *subject, int subject_len,
26112611
struct replay_opts *opts, int exit_code, int to_amend)
26122612
{
2613-
if (make_patch(commit, opts))
2614-
return -1;
2613+
if (commit) {
2614+
if (make_patch(commit, opts))
2615+
return -1;
2616+
} else if (copy_file(rebase_path_message(),
2617+
git_path_merge_msg(the_repository), 0666))
2618+
return error(_("unable to copy '%s' to '%s'"),
2619+
git_path_merge_msg(the_repository), rebase_path_message());
26152620

26162621
if (to_amend) {
26172622
if (intend_to_amend())
@@ -2626,9 +2631,18 @@ static int error_with_patch(struct commit *commit,
26262631
"\n"
26272632
" git rebase --continue\n"),
26282633
gpg_sign_opt_quoted(opts));
2629-
} else if (exit_code)
2630-
fprintf_ln(stderr, _("Could not apply %s... %.*s"),
2631-
short_commit_name(commit), subject_len, subject);
2634+
} else if (exit_code) {
2635+
if (commit)
2636+
fprintf_ln(stderr, _("Could not apply %s... %.*s"),
2637+
short_commit_name(commit), subject_len, subject);
2638+
else
2639+
/*
2640+
* We don't have the hash of the parent so
2641+
* just print the line from the todo file.
2642+
*/
2643+
fprintf_ln(stderr, _("Could not merge %.*s"),
2644+
subject_len, subject);
2645+
}
26322646

26332647
return exit_code;
26342648
}

t/t3430-rebase-merges.sh

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ Initial setup:
1313
-- B -- (first)
1414
/ \
1515
A - C - D - E - H (master)
16-
\ /
17-
F - G (second)
16+
\ \ /
17+
\ F - G (second)
18+
\
19+
Conflicting-G
1820
'
1921
. ./test-lib.sh
2022
. "$TEST_DIRECTORY"/lib-rebase.sh
@@ -49,7 +51,9 @@ test_expect_success 'setup' '
4951
git merge --no-commit G &&
5052
test_tick &&
5153
git commit -m H &&
52-
git tag -m H H
54+
git tag -m H H &&
55+
git checkout A &&
56+
test_commit conflicting-G G.t
5357
'
5458

5559
test_expect_success 'create completely different structure' '
@@ -72,7 +76,7 @@ test_expect_success 'create completely different structure' '
7276
EOF
7377
test_config sequence.editor \""$PWD"/replace-editor.sh\" &&
7478
test_tick &&
75-
git rebase -i -r A &&
79+
git rebase -i -r A master &&
7680
test_cmp_graph <<-\EOF
7781
* Merge the topic branch '\''onebranch'\''
7882
|\
@@ -125,7 +129,7 @@ test_expect_success '`reset` refuses to overwrite untracked files' '
125129
git rebase --abort
126130
'
127131

128-
test_expect_success 'failed `merge` writes patch (may be rescheduled, too)' '
132+
test_expect_success 'failed `merge -C` writes patch (may be rescheduled, too)' '
129133
test_when_finished "test_might_fail git rebase --abort" &&
130134
git checkout -b conflicting-merge A &&
131135
@@ -141,13 +145,25 @@ test_expect_success 'failed `merge` writes patch (may be rescheduled, too)' '
141145
142146
: fail because of merge conflict &&
143147
rm G.t .git/rebase-merge/patch &&
144-
git reset --hard &&
145-
test_commit conflicting-G G.t not-G conflicting-G &&
148+
git reset --hard conflicting-G &&
146149
test_must_fail git rebase --continue &&
147150
! grep "^merge -C .* G$" .git/rebase-merge/git-rebase-todo &&
148151
test_path_is_file .git/rebase-merge/patch
149152
'
150153

154+
SQ="'"
155+
test_expect_success 'failed `merge <branch>` does not crash' '
156+
test_when_finished "test_might_fail git rebase --abort" &&
157+
git checkout conflicting-G &&
158+
159+
echo "merge G" >script-from-scratch &&
160+
test_config sequence.editor \""$PWD"/replace-editor.sh\" &&
161+
test_tick &&
162+
test_must_fail git rebase -ir HEAD &&
163+
! grep "^merge G$" .git/rebase-merge/git-rebase-todo &&
164+
grep "^Merge branch ${SQ}G${SQ}$" .git/rebase-merge/message
165+
'
166+
151167
test_expect_success 'with a branch tip that was cherry-picked already' '
152168
git checkout -b already-upstream master &&
153169
base="$(git rev-parse --verify HEAD)" &&

0 commit comments

Comments
 (0)