Add changeToFixup field to MoveFixupCommitDown
This commit is contained in:
@@ -221,13 +221,13 @@ func moveTodosUp(todos []todo.Todo, todosToMove []Todo) ([]todo.Todo, error) {
|
||||
return todos, nil
|
||||
}
|
||||
|
||||
func MoveFixupCommitDown(fileName string, originalHash string, fixupHash string, commentChar byte) error {
|
||||
func MoveFixupCommitDown(fileName string, originalHash string, fixupHash string, changeToFixup bool, commentChar byte) error {
|
||||
todos, err := ReadRebaseTodoFile(fileName, commentChar)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
newTodos, err := moveFixupCommitDown(todos, originalHash, fixupHash)
|
||||
newTodos, err := moveFixupCommitDown(todos, originalHash, fixupHash, changeToFixup)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -235,7 +235,7 @@ func MoveFixupCommitDown(fileName string, originalHash string, fixupHash string,
|
||||
return WriteRebaseTodoFile(fileName, newTodos, commentChar)
|
||||
}
|
||||
|
||||
func moveFixupCommitDown(todos []todo.Todo, originalHash string, fixupHash string) ([]todo.Todo, error) {
|
||||
func moveFixupCommitDown(todos []todo.Todo, originalHash string, fixupHash string, changeToFixup bool) ([]todo.Todo, error) {
|
||||
isOriginal := func(t todo.Todo) bool {
|
||||
return (t.Command == todo.Pick || t.Command == todo.Merge) && equalHash(t.Commit, originalHash)
|
||||
}
|
||||
@@ -259,7 +259,9 @@ func moveFixupCommitDown(todos []todo.Todo, originalHash string, fixupHash strin
|
||||
|
||||
newTodos := MoveElement(todos, fixupIndex, originalIndex+1)
|
||||
|
||||
newTodos[originalIndex+1].Command = todo.Fixup
|
||||
if changeToFixup {
|
||||
newTodos[originalIndex+1].Command = todo.Fixup
|
||||
}
|
||||
|
||||
return newTodos, nil
|
||||
}
|
||||
|
||||
@@ -266,23 +266,40 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) {
|
||||
todos []todo.Todo
|
||||
originalHash string
|
||||
fixupHash string
|
||||
changeToFixup bool
|
||||
expectedTodos []todo.Todo
|
||||
expectedErr error
|
||||
}{
|
||||
{
|
||||
name: "fixup commit is the last commit",
|
||||
name: "fixup commit is the last commit (change to fixup)",
|
||||
todos: []todo.Todo{
|
||||
{Command: todo.Pick, Commit: "original"},
|
||||
{Command: todo.Pick, Commit: "fixup"},
|
||||
},
|
||||
originalHash: "original",
|
||||
fixupHash: "fixup",
|
||||
originalHash: "original",
|
||||
fixupHash: "fixup",
|
||||
changeToFixup: true,
|
||||
expectedTodos: []todo.Todo{
|
||||
{Command: todo.Pick, Commit: "original"},
|
||||
{Command: todo.Fixup, Commit: "fixup"},
|
||||
},
|
||||
expectedErr: nil,
|
||||
},
|
||||
{
|
||||
name: "fixup commit is the last commit (don't change to fixup)",
|
||||
todos: []todo.Todo{
|
||||
{Command: todo.Pick, Commit: "original"},
|
||||
{Command: todo.Pick, Commit: "fixup"},
|
||||
},
|
||||
originalHash: "original",
|
||||
fixupHash: "fixup",
|
||||
changeToFixup: false,
|
||||
expectedTodos: []todo.Todo{
|
||||
{Command: todo.Pick, Commit: "original"},
|
||||
{Command: todo.Pick, Commit: "fixup"},
|
||||
},
|
||||
expectedErr: nil,
|
||||
},
|
||||
{
|
||||
name: "fixup commit is separated from original commit",
|
||||
todos: []todo.Todo{
|
||||
@@ -290,8 +307,9 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) {
|
||||
{Command: todo.Pick, Commit: "other"},
|
||||
{Command: todo.Pick, Commit: "fixup"},
|
||||
},
|
||||
originalHash: "original",
|
||||
fixupHash: "fixup",
|
||||
originalHash: "original",
|
||||
fixupHash: "fixup",
|
||||
changeToFixup: true,
|
||||
expectedTodos: []todo.Todo{
|
||||
{Command: todo.Pick, Commit: "original"},
|
||||
{Command: todo.Fixup, Commit: "fixup"},
|
||||
@@ -306,8 +324,9 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) {
|
||||
{Command: todo.Pick, Commit: "other"},
|
||||
{Command: todo.Pick, Commit: "fixup"},
|
||||
},
|
||||
originalHash: "original",
|
||||
fixupHash: "fixup",
|
||||
originalHash: "original",
|
||||
fixupHash: "fixup",
|
||||
changeToFixup: true,
|
||||
expectedTodos: []todo.Todo{
|
||||
{Command: todo.Merge, Commit: "original"},
|
||||
{Command: todo.Fixup, Commit: "fixup"},
|
||||
@@ -324,6 +343,7 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) {
|
||||
},
|
||||
originalHash: "original",
|
||||
fixupHash: "fixup",
|
||||
changeToFixup: true,
|
||||
expectedTodos: nil,
|
||||
expectedErr: errors.New("Expected exactly one original hash, found 2"),
|
||||
},
|
||||
@@ -336,6 +356,7 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) {
|
||||
},
|
||||
originalHash: "original",
|
||||
fixupHash: "fixup",
|
||||
changeToFixup: true,
|
||||
expectedTodos: nil,
|
||||
expectedErr: errors.New("Expected exactly one fixup hash, found 2"),
|
||||
},
|
||||
@@ -346,6 +367,7 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) {
|
||||
},
|
||||
originalHash: "original",
|
||||
fixupHash: "fixup",
|
||||
changeToFixup: true,
|
||||
expectedTodos: nil,
|
||||
expectedErr: errors.New("Expected exactly one fixup hash, found 0"),
|
||||
},
|
||||
@@ -356,6 +378,7 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) {
|
||||
},
|
||||
originalHash: "original",
|
||||
fixupHash: "fixup",
|
||||
changeToFixup: true,
|
||||
expectedTodos: nil,
|
||||
expectedErr: errors.New("Expected exactly one original hash, found 0"),
|
||||
},
|
||||
@@ -363,7 +386,7 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) {
|
||||
|
||||
for _, scenario := range scenarios {
|
||||
t.Run(scenario.name, func(t *testing.T) {
|
||||
actualTodos, actualErr := moveFixupCommitDown(scenario.todos, scenario.originalHash, scenario.fixupHash)
|
||||
actualTodos, actualErr := moveFixupCommitDown(scenario.todos, scenario.originalHash, scenario.fixupHash, scenario.changeToFixup)
|
||||
|
||||
if scenario.expectedErr == nil {
|
||||
assert.NoError(t, actualErr)
|
||||
|
||||
Reference in New Issue
Block a user