Skip to content

Commit 5321101

Browse files
committed
Use 'break' instead of 'edit' for BeginInteractiveRebaseForCommit with merge commit
BeginInteractiveRebaseForCommit is used for all the patch commands, and for rewording. It works by setting the commit we want to stop at to 'edit'; this doesn't work for merge commits. This wasn't a problem for the patch commands so far, because you typically don't use custom patches with merge commits (although we don't prevent this; maybe we should?). However, it was a problem when you tried to reword a merge commit; this previously failed with an error, as the test added in the previous commit demonstrated. Also, we want to add a new patch command that has to stop *before* the selected commit (pull patch to new commit before the original one), and this wouldn't work for the first commit in a feature branch, because it would have to set the last commit before that to 'edit', which isn't possible if that's a merge (which is likely). To fix all this, use a 'break' before the selected commit if the commit is a merge. It is important that we only do it in that case and not always, otherwise we would break the new regression tests that were added a few commits ago.
1 parent 50b2aa5 commit 5321101

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

pkg/commands/git_commands/rebase.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,19 @@ func (self *RebaseCommands) SquashAllAboveFixupCommits(commit *models.Commit) er
400400
func (self *RebaseCommands) BeginInteractiveRebaseForCommit(
401401
commits []*models.Commit, commitIndex int, keepCommitsThatBecomeEmpty bool,
402402
) error {
403-
return self.BeginInteractiveRebaseForCommitRange(commits, commitIndex, commitIndex, keepCommitsThatBecomeEmpty)
403+
if commitIndex < len(commits) && commits[commitIndex].IsMerge() {
404+
if self.config.NeedsGpgSubprocessForCommit() {
405+
return errors.New(self.Tr.DisabledForGPG)
406+
}
407+
408+
return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{
409+
baseHashOrRoot: getBaseHashOrRoot(commits, commitIndex),
410+
instruction: daemon.NewInsertBreakInstruction(),
411+
keepCommitsThatBecomeEmpty: keepCommitsThatBecomeEmpty,
412+
}).Run()
413+
} else {
414+
return self.BeginInteractiveRebaseForCommitRange(commits, commitIndex, commitIndex, keepCommitsThatBecomeEmpty)
415+
}
404416
}
405417

406418
func (self *RebaseCommands) BeginInteractiveRebaseForCommitRange(

pkg/integration/tests/interactive_rebase/reword_merge_commit.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,11 @@ var RewordMergeCommit = NewIntegrationTest(NewIntegrationTestArgs{
4040
Type("renamed merge").
4141
Confirm()
4242
}).
43-
/* EXPECTED:
4443
Lines(
4544
Contains("CI ◯ two"),
4645
Contains("CI ⏣─╮ renamed merge").IsSelected(),
4746
Contains("CI │ ◯ one"),
4847
Contains("CI ◯ ╯ base"),
4948
)
50-
ACTUAL: */
51-
Tap(func() {
52-
t.ExpectPopup().Alert().Title(Equals("Error")).
53-
Content(Contains("error: 'edit' does not accept merge commits"))
54-
})
5549
},
5650
})

0 commit comments

Comments
 (0)