mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-28 16:02:01 +03:00
rearranging todo items while interactively rebasing
This commit is contained in:
committed by
Jesse Duffield Duffield
parent
cdc50e8557
commit
f6b3a9b184
@ -598,7 +598,7 @@ func (c *GitCommand) MoveCommitDown(commits []*Commit, index int) error {
|
||||
if len(commits) <= index+2 {
|
||||
// assuming they aren't picking the bottom commit
|
||||
// TODO: support more than say 30 commits and ensure this logic is correct, and i18n
|
||||
return errors.New("Not enough room")
|
||||
return errors.New(c.Tr.SLocalize("NoRoom"))
|
||||
}
|
||||
|
||||
todo := ""
|
||||
@ -696,6 +696,7 @@ func (c *GitCommand) AmendTo(sha string) error {
|
||||
return c.OSCommand.RunCommand(fmt.Sprintf("git %s rebase --interactive --autostash --autosquash %s^", c.OSCommand.Platform.skipEditorArg, sha))
|
||||
}
|
||||
|
||||
// EditRebaseTodo sets the action at a given index in the git-rebase-todo file
|
||||
func (c *GitCommand) EditRebaseTodo(index int, action string) error {
|
||||
fileName := ".git/rebase-merge/git-rebase-todo"
|
||||
bytes, err := ioutil.ReadFile(fileName)
|
||||
@ -713,6 +714,24 @@ func (c *GitCommand) EditRebaseTodo(index int, action string) error {
|
||||
return ioutil.WriteFile(fileName, []byte(result), 0644)
|
||||
}
|
||||
|
||||
// MoveTodoDown moves a rebase todo item down by one position
|
||||
func (c *GitCommand) MoveTodoDown(index int) error {
|
||||
fileName := ".git/rebase-merge/git-rebase-todo"
|
||||
bytes, err := ioutil.ReadFile(fileName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
content := strings.Split(string(bytes), "\n")
|
||||
contentIndex := len(content) - 2 - index
|
||||
|
||||
rearrangedContent := append(content[0:contentIndex-1], content[contentIndex], content[contentIndex-1])
|
||||
rearrangedContent = append(rearrangedContent, content[contentIndex+1:]...)
|
||||
result := strings.Join(rearrangedContent, "\n")
|
||||
|
||||
return ioutil.WriteFile(fileName, []byte(result), 0644)
|
||||
}
|
||||
|
||||
// Revert reverts the selected commit by sha
|
||||
func (c *GitCommand) Revert(sha string) error {
|
||||
return c.OSCommand.RunCommand(fmt.Sprintf("git revert %s", sha))
|
||||
|
Reference in New Issue
Block a user