diff --git a/pkg/commands/git_commands/commit_loader.go b/pkg/commands/git_commands/commit_loader.go index bf31bc287..2f4556bb9 100644 --- a/pkg/commands/git_commands/commit_loader.go +++ b/pkg/commands/git_commands/commit_loader.go @@ -388,15 +388,13 @@ func (self *CommitLoader) getConflictedCommit(todos []todo.Todo) *models.Commit return nil } - amendFileExists := false - if _, err := os.Stat(filepath.Join(self.repoPaths.WorktreeGitDirPath(), "rebase-merge/amend")); err == nil { - amendFileExists = true - } + amendFileExists, _ := self.os.FileExists(filepath.Join(self.repoPaths.WorktreeGitDirPath(), "rebase-merge/amend")) + messageFileExists, _ := self.os.FileExists(filepath.Join(self.repoPaths.WorktreeGitDirPath(), "rebase-merge/message")) - return self.getConflictedCommitImpl(todos, doneTodos, amendFileExists) + return self.getConflictedCommitImpl(todos, doneTodos, amendFileExists, messageFileExists) } -func (self *CommitLoader) getConflictedCommitImpl(todos []todo.Todo, doneTodos []todo.Todo, amendFileExists bool) *models.Commit { +func (self *CommitLoader) getConflictedCommitImpl(todos []todo.Todo, doneTodos []todo.Todo, amendFileExists bool, messageFileExists bool) *models.Commit { // Should never be possible, but just to be safe: if len(doneTodos) == 0 { self.Log.Error("no done entries in rebase-merge/done file") @@ -449,6 +447,14 @@ func (self *CommitLoader) getConflictedCommitImpl(todos []todo.Todo, doneTodos [ // command was successful, otherwise it wasn't return nil } + + if !messageFileExists { + // As an additional check, see if the "message" file exists; if it + // doesn't, it must be because a multi-commit cherry-pick or revert + // was performed in the meantime, which deleted both the amend file + // and the message file. + return nil + } } // I don't think this is ever possible, but again, just to be safe: diff --git a/pkg/commands/git_commands/commit_loader_test.go b/pkg/commands/git_commands/commit_loader_test.go index 652fb759c..e3e8c346b 100644 --- a/pkg/commands/git_commands/commit_loader_test.go +++ b/pkg/commands/git_commands/commit_loader_test.go @@ -328,11 +328,12 @@ func TestGetCommits(t *testing.T) { func TestCommitLoader_getConflictedCommitImpl(t *testing.T) { scenarios := []struct { - testName string - todos []todo.Todo - doneTodos []todo.Todo - amendFileExists bool - expectedResult *models.Commit + testName string + todos []todo.Todo + doneTodos []todo.Todo + amendFileExists bool + messageFileExists bool + expectedResult *models.Commit }{ { testName: "no done todos", @@ -475,7 +476,7 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) { expectedResult: nil, }, { - testName: "'edit' without amend file", + testName: "'edit' without amend file but message file", todos: []todo.Todo{}, doneTodos: []todo.Todo{ { @@ -483,13 +484,27 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) { Commit: "fa1afe1", }, }, - amendFileExists: false, + amendFileExists: false, + messageFileExists: true, expectedResult: &models.Commit{ Hash: "fa1afe1", Action: todo.Edit, Status: models.StatusConflicted, }, }, + { + testName: "'edit' without amend and without message file", + todos: []todo.Todo{}, + doneTodos: []todo.Todo{ + { + Command: todo.Edit, + Commit: "fa1afe1", + }, + }, + amendFileExists: false, + messageFileExists: false, + expectedResult: nil, + }, } for _, scenario := range scenarios { t.Run(scenario.testName, func(t *testing.T) { @@ -508,7 +523,7 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) { }, } - hash := builder.getConflictedCommitImpl(scenario.todos, scenario.doneTodos, scenario.amendFileExists) + hash := builder.getConflictedCommitImpl(scenario.todos, scenario.doneTodos, scenario.amendFileExists, scenario.messageFileExists) assert.Equal(t, scenario.expectedResult, hash) }) } diff --git a/pkg/integration/tests/interactive_rebase/revert_during_rebase_when_stopped_on_edit.go b/pkg/integration/tests/interactive_rebase/revert_during_rebase_when_stopped_on_edit.go index a2138e874..1db0f0370 100644 --- a/pkg/integration/tests/interactive_rebase/revert_during_rebase_when_stopped_on_edit.go +++ b/pkg/integration/tests/interactive_rebase/revert_during_rebase_when_stopped_on_edit.go @@ -45,7 +45,6 @@ var RevertDuringRebaseWhenStoppedOnEdit = NewIntegrationTest(NewIntegrationTestA ). Press("X"). Lines( - /* EXPECTED: Contains("pick").Contains("commit 04"), Contains(`<-- YOU ARE HERE --- Revert "commit 01"`).IsSelected(), Contains(`Revert "commit 02"`), @@ -53,15 +52,6 @@ var RevertDuringRebaseWhenStoppedOnEdit = NewIntegrationTest(NewIntegrationTestA Contains("commit 02"), Contains("commit 01"), Contains("master commit"), - ACTUAL: */ - Contains("pick").Contains("commit 04"), - Contains("edit").Contains("<-- CONFLICT --- commit 03").IsSelected(), - Contains(`Revert "commit 01"`), - Contains(`Revert "commit 02"`), - Contains("commit 03"), - Contains("commit 02"), - Contains("commit 01"), - Contains("master commit"), ) }, }) diff --git a/pkg/integration/tests/interactive_rebase/revert_multiple_commits_in_interactive_rebase.go b/pkg/integration/tests/interactive_rebase/revert_multiple_commits_in_interactive_rebase.go index 6a6dc771a..2953e3c3a 100644 --- a/pkg/integration/tests/interactive_rebase/revert_multiple_commits_in_interactive_rebase.go +++ b/pkg/integration/tests/interactive_rebase/revert_multiple_commits_in_interactive_rebase.go @@ -84,7 +84,6 @@ var RevertMultipleCommitsInInteractiveRebase = NewIntegrationTest(NewIntegration t.Views().Commits(). Lines( - /* EXPECTED: Contains("pick").Contains("CI unrelated change 3"), Contains("pick").Contains("CI unrelated change 2"), Contains(`CI ◯ <-- YOU ARE HERE --- Revert "unrelated change 1"`), @@ -93,16 +92,6 @@ var RevertMultipleCommitsInInteractiveRebase = NewIntegrationTest(NewIntegration Contains("CI ◯ add first line"), Contains("CI ◯ unrelated change 1"), Contains("CI ◯ add empty file"), - ACTUAL: */ - Contains("pick").Contains("CI unrelated change 3"), - Contains("pick").Contains("CI unrelated change 2"), - Contains("edit CI <-- CONFLICT --- add second line"), - Contains(`CI ◯ Revert "unrelated change 1"`), - Contains(`CI ◯ Revert "add first line"`), - Contains("CI ◯ add second line"), - Contains("CI ◯ add first line"), - Contains("CI ◯ unrelated change 1"), - Contains("CI ◯ add empty file"), ) t.Views().Options().Content(Contains("View rebase options: m"))