Fix the bug described in the previous commit

What happens here is that when stopping on an "edit" todo entry, we rely on the
assumption that if the .git/rebase-merge/amend file exists, the command was
successful, and if it doesn't, there was a conflict. The problem is that when
you stop on an edit command, and then run a multi-commit cherry-pick or rebase,
this will delete the amend file. You may or may not consider this a bug in git;
to work around it, we also check the existence of the rebase-merge/message file,
which will be deleted as well by the cherry-pick or revert.
This commit is contained in:
Stefan Haller 2024-06-14 14:36:31 +02:00
parent 9b88052a4e
commit 5ba8d42c80
4 changed files with 35 additions and 35 deletions

View file

@ -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)
})
}