mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-17 00:18:05 +02:00
Add changeToFixup field to MoveFixupCommitDown
This commit is contained in:
@ -246,16 +246,18 @@ func (self *ChangeTodoActionsInstruction) run(common *common.Common) error {
|
|||||||
|
|
||||||
// Takes the hash of some commit, and the hash of a fixup commit that was created
|
// Takes the hash of some commit, and the hash of a fixup commit that was created
|
||||||
// at the end of the branch, then moves the fixup commit down to right after the
|
// at the end of the branch, then moves the fixup commit down to right after the
|
||||||
// original commit, changing its type to "fixup"
|
// original commit, changing its type to "fixup" (only if ChangeToFixup is true)
|
||||||
type MoveFixupCommitDownInstruction struct {
|
type MoveFixupCommitDownInstruction struct {
|
||||||
OriginalHash string
|
OriginalHash string
|
||||||
FixupHash string
|
FixupHash string
|
||||||
|
ChangeToFixup bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMoveFixupCommitDownInstruction(originalHash string, fixupHash string) Instruction {
|
func NewMoveFixupCommitDownInstruction(originalHash string, fixupHash string, changeToFixup bool) Instruction {
|
||||||
return &MoveFixupCommitDownInstruction{
|
return &MoveFixupCommitDownInstruction{
|
||||||
OriginalHash: originalHash,
|
OriginalHash: originalHash,
|
||||||
FixupHash: fixupHash,
|
FixupHash: fixupHash,
|
||||||
|
ChangeToFixup: changeToFixup,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,7 +271,7 @@ func (self *MoveFixupCommitDownInstruction) SerializedInstructions() string {
|
|||||||
|
|
||||||
func (self *MoveFixupCommitDownInstruction) run(common *common.Common) error {
|
func (self *MoveFixupCommitDownInstruction) run(common *common.Common) error {
|
||||||
return handleInteractiveRebase(common, func(path string) error {
|
return handleInteractiveRebase(common, func(path string) error {
|
||||||
return utils.MoveFixupCommitDown(path, self.OriginalHash, self.FixupHash, getCommentChar())
|
return utils.MoveFixupCommitDown(path, self.OriginalHash, self.FixupHash, self.ChangeToFixup, getCommentChar())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,7 +302,7 @@ func (self *RebaseCommands) AmendTo(commits []*models.Commit, commitIndex int) e
|
|||||||
return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{
|
return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{
|
||||||
baseHashOrRoot: getBaseHashOrRoot(commits, commitIndex+1),
|
baseHashOrRoot: getBaseHashOrRoot(commits, commitIndex+1),
|
||||||
overrideEditor: true,
|
overrideEditor: true,
|
||||||
instruction: daemon.NewMoveFixupCommitDownInstruction(commit.Hash, fixupHash),
|
instruction: daemon.NewMoveFixupCommitDownInstruction(commit.Hash, fixupHash, true),
|
||||||
}).Run()
|
}).Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,13 +221,13 @@ func moveTodosUp(todos []todo.Todo, todosToMove []Todo) ([]todo.Todo, error) {
|
|||||||
return todos, nil
|
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)
|
todos, err := ReadRebaseTodoFile(fileName, commentChar)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
newTodos, err := moveFixupCommitDown(todos, originalHash, fixupHash)
|
newTodos, err := moveFixupCommitDown(todos, originalHash, fixupHash, changeToFixup)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -235,7 +235,7 @@ func MoveFixupCommitDown(fileName string, originalHash string, fixupHash string,
|
|||||||
return WriteRebaseTodoFile(fileName, newTodos, commentChar)
|
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 {
|
isOriginal := func(t todo.Todo) bool {
|
||||||
return (t.Command == todo.Pick || t.Command == todo.Merge) && equalHash(t.Commit, originalHash)
|
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 := MoveElement(todos, fixupIndex, originalIndex+1)
|
||||||
|
|
||||||
newTodos[originalIndex+1].Command = todo.Fixup
|
if changeToFixup {
|
||||||
|
newTodos[originalIndex+1].Command = todo.Fixup
|
||||||
|
}
|
||||||
|
|
||||||
return newTodos, nil
|
return newTodos, nil
|
||||||
}
|
}
|
||||||
|
@ -266,23 +266,40 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) {
|
|||||||
todos []todo.Todo
|
todos []todo.Todo
|
||||||
originalHash string
|
originalHash string
|
||||||
fixupHash string
|
fixupHash string
|
||||||
|
changeToFixup bool
|
||||||
expectedTodos []todo.Todo
|
expectedTodos []todo.Todo
|
||||||
expectedErr error
|
expectedErr error
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "fixup commit is the last commit",
|
name: "fixup commit is the last commit (change to fixup)",
|
||||||
todos: []todo.Todo{
|
todos: []todo.Todo{
|
||||||
{Command: todo.Pick, Commit: "original"},
|
{Command: todo.Pick, Commit: "original"},
|
||||||
{Command: todo.Pick, Commit: "fixup"},
|
{Command: todo.Pick, Commit: "fixup"},
|
||||||
},
|
},
|
||||||
originalHash: "original",
|
originalHash: "original",
|
||||||
fixupHash: "fixup",
|
fixupHash: "fixup",
|
||||||
|
changeToFixup: true,
|
||||||
expectedTodos: []todo.Todo{
|
expectedTodos: []todo.Todo{
|
||||||
{Command: todo.Pick, Commit: "original"},
|
{Command: todo.Pick, Commit: "original"},
|
||||||
{Command: todo.Fixup, Commit: "fixup"},
|
{Command: todo.Fixup, Commit: "fixup"},
|
||||||
},
|
},
|
||||||
expectedErr: nil,
|
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",
|
name: "fixup commit is separated from original commit",
|
||||||
todos: []todo.Todo{
|
todos: []todo.Todo{
|
||||||
@ -290,8 +307,9 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) {
|
|||||||
{Command: todo.Pick, Commit: "other"},
|
{Command: todo.Pick, Commit: "other"},
|
||||||
{Command: todo.Pick, Commit: "fixup"},
|
{Command: todo.Pick, Commit: "fixup"},
|
||||||
},
|
},
|
||||||
originalHash: "original",
|
originalHash: "original",
|
||||||
fixupHash: "fixup",
|
fixupHash: "fixup",
|
||||||
|
changeToFixup: true,
|
||||||
expectedTodos: []todo.Todo{
|
expectedTodos: []todo.Todo{
|
||||||
{Command: todo.Pick, Commit: "original"},
|
{Command: todo.Pick, Commit: "original"},
|
||||||
{Command: todo.Fixup, Commit: "fixup"},
|
{Command: todo.Fixup, Commit: "fixup"},
|
||||||
@ -306,8 +324,9 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) {
|
|||||||
{Command: todo.Pick, Commit: "other"},
|
{Command: todo.Pick, Commit: "other"},
|
||||||
{Command: todo.Pick, Commit: "fixup"},
|
{Command: todo.Pick, Commit: "fixup"},
|
||||||
},
|
},
|
||||||
originalHash: "original",
|
originalHash: "original",
|
||||||
fixupHash: "fixup",
|
fixupHash: "fixup",
|
||||||
|
changeToFixup: true,
|
||||||
expectedTodos: []todo.Todo{
|
expectedTodos: []todo.Todo{
|
||||||
{Command: todo.Merge, Commit: "original"},
|
{Command: todo.Merge, Commit: "original"},
|
||||||
{Command: todo.Fixup, Commit: "fixup"},
|
{Command: todo.Fixup, Commit: "fixup"},
|
||||||
@ -324,6 +343,7 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) {
|
|||||||
},
|
},
|
||||||
originalHash: "original",
|
originalHash: "original",
|
||||||
fixupHash: "fixup",
|
fixupHash: "fixup",
|
||||||
|
changeToFixup: true,
|
||||||
expectedTodos: nil,
|
expectedTodos: nil,
|
||||||
expectedErr: errors.New("Expected exactly one original hash, found 2"),
|
expectedErr: errors.New("Expected exactly one original hash, found 2"),
|
||||||
},
|
},
|
||||||
@ -336,6 +356,7 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) {
|
|||||||
},
|
},
|
||||||
originalHash: "original",
|
originalHash: "original",
|
||||||
fixupHash: "fixup",
|
fixupHash: "fixup",
|
||||||
|
changeToFixup: true,
|
||||||
expectedTodos: nil,
|
expectedTodos: nil,
|
||||||
expectedErr: errors.New("Expected exactly one fixup hash, found 2"),
|
expectedErr: errors.New("Expected exactly one fixup hash, found 2"),
|
||||||
},
|
},
|
||||||
@ -346,6 +367,7 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) {
|
|||||||
},
|
},
|
||||||
originalHash: "original",
|
originalHash: "original",
|
||||||
fixupHash: "fixup",
|
fixupHash: "fixup",
|
||||||
|
changeToFixup: true,
|
||||||
expectedTodos: nil,
|
expectedTodos: nil,
|
||||||
expectedErr: errors.New("Expected exactly one fixup hash, found 0"),
|
expectedErr: errors.New("Expected exactly one fixup hash, found 0"),
|
||||||
},
|
},
|
||||||
@ -356,6 +378,7 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) {
|
|||||||
},
|
},
|
||||||
originalHash: "original",
|
originalHash: "original",
|
||||||
fixupHash: "fixup",
|
fixupHash: "fixup",
|
||||||
|
changeToFixup: true,
|
||||||
expectedTodos: nil,
|
expectedTodos: nil,
|
||||||
expectedErr: errors.New("Expected exactly one original hash, found 0"),
|
expectedErr: errors.New("Expected exactly one original hash, found 0"),
|
||||||
},
|
},
|
||||||
@ -363,7 +386,7 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) {
|
|||||||
|
|
||||||
for _, scenario := range scenarios {
|
for _, scenario := range scenarios {
|
||||||
t.Run(scenario.name, func(t *testing.T) {
|
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 {
|
if scenario.expectedErr == nil {
|
||||||
assert.NoError(t, actualErr)
|
assert.NoError(t, actualErr)
|
||||||
|
Reference in New Issue
Block a user