mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-03-21 21:47:32 +02:00
change type of cherryPickedCommits from []string to []*Commit
This commit is contained in:
parent
639df512f3
commit
f4938deaae
@ -746,11 +746,11 @@ func (c *GitCommand) Revert(sha string) error {
|
|||||||
return c.OSCommand.RunCommand(fmt.Sprintf("git revert %s", sha))
|
return c.OSCommand.RunCommand(fmt.Sprintf("git revert %s", sha))
|
||||||
}
|
}
|
||||||
|
|
||||||
// CherryPickShas begins an interactive rebase with the given shas being cherry picked onto HEAD
|
// CherryPickCommits begins an interactive rebase with the given shas being cherry picked onto HEAD
|
||||||
func (c *GitCommand) CherryPickShas(shas []string) error {
|
func (c *GitCommand) CherryPickCommits(commits []*Commit) error {
|
||||||
todo := ""
|
todo := ""
|
||||||
for _, sha := range shas {
|
for _, commit := range commits {
|
||||||
todo = "pick " + sha + "\n" + todo
|
todo = "pick " + commit.Sha + " " + commit.Name + "\n" + todo
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd, err := c.PrepareInteractiveRebaseCommand("HEAD", todo, false)
|
cmd, err := c.PrepareInteractiveRebaseCommand("HEAD", todo, false)
|
||||||
|
@ -23,21 +23,21 @@ import (
|
|||||||
|
|
||||||
// CommitListBuilder returns a list of Branch objects for the current repo
|
// CommitListBuilder returns a list of Branch objects for the current repo
|
||||||
type CommitListBuilder struct {
|
type CommitListBuilder struct {
|
||||||
Log *logrus.Entry
|
Log *logrus.Entry
|
||||||
GitCommand *commands.GitCommand
|
GitCommand *commands.GitCommand
|
||||||
OSCommand *commands.OSCommand
|
OSCommand *commands.OSCommand
|
||||||
Tr *i18n.Localizer
|
Tr *i18n.Localizer
|
||||||
CherryPickedShas []string
|
CherryPickedCommits []*commands.Commit
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCommitListBuilder builds a new commit list builder
|
// NewCommitListBuilder builds a new commit list builder
|
||||||
func NewCommitListBuilder(log *logrus.Entry, gitCommand *commands.GitCommand, osCommand *commands.OSCommand, tr *i18n.Localizer, cherryPickedShas []string) (*CommitListBuilder, error) {
|
func NewCommitListBuilder(log *logrus.Entry, gitCommand *commands.GitCommand, osCommand *commands.OSCommand, tr *i18n.Localizer, cherryPickedCommits []*commands.Commit) (*CommitListBuilder, error) {
|
||||||
return &CommitListBuilder{
|
return &CommitListBuilder{
|
||||||
Log: log,
|
Log: log,
|
||||||
GitCommand: gitCommand,
|
GitCommand: gitCommand,
|
||||||
OSCommand: osCommand,
|
OSCommand: osCommand,
|
||||||
Tr: tr,
|
Tr: tr,
|
||||||
CherryPickedShas: cherryPickedShas,
|
CherryPickedCommits: cherryPickedCommits,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,8 +159,8 @@ func (c *CommitListBuilder) setCommitMergedStatuses(commits []*commands.Commit)
|
|||||||
|
|
||||||
func (c *CommitListBuilder) setCommitCherryPickStatuses(commits []*commands.Commit) ([]*commands.Commit, error) {
|
func (c *CommitListBuilder) setCommitCherryPickStatuses(commits []*commands.Commit) ([]*commands.Commit, error) {
|
||||||
for _, commit := range commits {
|
for _, commit := range commits {
|
||||||
for _, sha := range c.CherryPickedShas {
|
for _, cherryPickedCommit := range c.CherryPickedCommits {
|
||||||
if commit.Sha == sha {
|
if commit.Sha == cherryPickedCommit.Sha {
|
||||||
commit.Copied = true
|
commit.Copied = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package gui
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
|
|
||||||
@ -42,7 +41,7 @@ func (gui *Gui) handleCommitSelect(g *gocui.Gui, v *gocui.View) error {
|
|||||||
|
|
||||||
func (gui *Gui) refreshCommits(g *gocui.Gui) error {
|
func (gui *Gui) refreshCommits(g *gocui.Gui) error {
|
||||||
g.Update(func(*gocui.Gui) error {
|
g.Update(func(*gocui.Gui) error {
|
||||||
builder, err := git.NewCommitListBuilder(gui.Log, gui.GitCommand, gui.OSCommand, gui.Tr, gui.State.CherryPickedShas)
|
builder, err := git.NewCommitListBuilder(gui.Log, gui.GitCommand, gui.OSCommand, gui.Tr, gui.State.CherryPickedCommits)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -352,36 +351,34 @@ func (gui *Gui) handleCommitRevert(g *gocui.Gui, v *gocui.View) error {
|
|||||||
|
|
||||||
func (gui *Gui) handleCopyCommit(g *gocui.Gui, v *gocui.View) error {
|
func (gui *Gui) handleCopyCommit(g *gocui.Gui, v *gocui.View) error {
|
||||||
// get currently selected commit, add the sha to state.
|
// get currently selected commit, add the sha to state.
|
||||||
sha := gui.State.Commits[gui.State.Panels.Commits.SelectedLine].Sha
|
commit := gui.State.Commits[gui.State.Panels.Commits.SelectedLine]
|
||||||
|
|
||||||
// we will un-copy it if it's already copied
|
// we will un-copy it if it's already copied
|
||||||
for index, cherryPickedSha := range gui.State.CherryPickedShas {
|
for index, cherryPickedCommit := range gui.State.CherryPickedCommits {
|
||||||
if sha == cherryPickedSha {
|
if commit.Sha == cherryPickedCommit.Sha {
|
||||||
gui.State.CherryPickedShas = append(gui.State.CherryPickedShas[0:index], gui.State.CherryPickedShas[index+1:]...)
|
gui.State.CherryPickedCommits = append(gui.State.CherryPickedCommits[0:index], gui.State.CherryPickedCommits[index+1:]...)
|
||||||
gui.Log.Info("removed copied sha. New shas:\n" + strings.Join(gui.State.CherryPickedShas, "\n"))
|
|
||||||
return gui.refreshCommits(gui.g)
|
return gui.refreshCommits(gui.g)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.addCommitToCherryPickedShas(gui.State.Panels.Commits.SelectedLine)
|
gui.addCommitToCherryPickedCommits(gui.State.Panels.Commits.SelectedLine)
|
||||||
return gui.refreshCommits(gui.g)
|
return gui.refreshCommits(gui.g)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) addCommitToCherryPickedShas(index int) {
|
func (gui *Gui) addCommitToCherryPickedCommits(index int) {
|
||||||
defer func() { gui.Log.Info("new copied shas:\n" + strings.Join(gui.State.CherryPickedShas, "\n")) }()
|
|
||||||
|
|
||||||
// not super happy with modifying the state of the Commits array here
|
// not super happy with modifying the state of the Commits array here
|
||||||
// but the alternative would be very tricky
|
// but the alternative would be very tricky
|
||||||
gui.State.Commits[index].Copied = true
|
gui.State.Commits[index].Copied = true
|
||||||
|
|
||||||
newShas := []string{}
|
newCommits := []*commands.Commit{}
|
||||||
for _, commit := range gui.State.Commits {
|
for _, commit := range gui.State.Commits {
|
||||||
if commit.Copied {
|
if commit.Copied {
|
||||||
newShas = append(newShas, commit.Sha)
|
// duplicating just the things we need to put in the rebase TODO list
|
||||||
|
newCommits = append(newCommits, &commands.Commit{Name: commit.Name, Sha: commit.Sha})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.State.CherryPickedShas = newShas
|
gui.State.CherryPickedCommits = newCommits
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) handleCopyCommitRange(g *gocui.Gui, v *gocui.View) error {
|
func (gui *Gui) handleCopyCommitRange(g *gocui.Gui, v *gocui.View) error {
|
||||||
@ -399,7 +396,7 @@ func (gui *Gui) handleCopyCommitRange(g *gocui.Gui, v *gocui.View) error {
|
|||||||
gui.Log.Info("commit copy start index: " + strconv.Itoa(startIndex))
|
gui.Log.Info("commit copy start index: " + strconv.Itoa(startIndex))
|
||||||
|
|
||||||
for index := startIndex; index <= gui.State.Panels.Commits.SelectedLine; index++ {
|
for index := startIndex; index <= gui.State.Panels.Commits.SelectedLine; index++ {
|
||||||
gui.addCommitToCherryPickedShas(index)
|
gui.addCommitToCherryPickedCommits(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
return gui.refreshCommits(gui.g)
|
return gui.refreshCommits(gui.g)
|
||||||
@ -408,8 +405,7 @@ func (gui *Gui) handleCopyCommitRange(g *gocui.Gui, v *gocui.View) error {
|
|||||||
// HandlePasteCommits begins a cherry-pick rebase with the commits the user has copied
|
// HandlePasteCommits begins a cherry-pick rebase with the commits the user has copied
|
||||||
func (gui *Gui) HandlePasteCommits(g *gocui.Gui, v *gocui.View) error {
|
func (gui *Gui) HandlePasteCommits(g *gocui.Gui, v *gocui.View) error {
|
||||||
return gui.createConfirmationPanel(g, v, gui.Tr.SLocalize("CherryPick"), gui.Tr.SLocalize("SureCherryPick"), func(g *gocui.Gui, v *gocui.View) error {
|
return gui.createConfirmationPanel(g, v, gui.Tr.SLocalize("CherryPick"), gui.Tr.SLocalize("SureCherryPick"), func(g *gocui.Gui, v *gocui.View) error {
|
||||||
err := gui.GitCommand.CherryPickShas(gui.State.CherryPickedShas)
|
err := gui.GitCommand.CherryPickCommits(gui.State.CherryPickedCommits)
|
||||||
return gui.handleGenericMergeCommandResult(err)
|
return gui.handleGenericMergeCommandResult(err)
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -123,29 +123,29 @@ type panelStates struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type guiState struct {
|
type guiState struct {
|
||||||
Files []*commands.File
|
Files []*commands.File
|
||||||
Branches []*commands.Branch
|
Branches []*commands.Branch
|
||||||
Commits []*commands.Commit
|
Commits []*commands.Commit
|
||||||
StashEntries []*commands.StashEntry
|
StashEntries []*commands.StashEntry
|
||||||
PreviousView string
|
PreviousView string
|
||||||
Platform commands.Platform
|
Platform commands.Platform
|
||||||
Updating bool
|
Updating bool
|
||||||
Panels *panelStates
|
Panels *panelStates
|
||||||
WorkingTreeState string // one of "merging", "rebasing", "normal"
|
WorkingTreeState string // one of "merging", "rebasing", "normal"
|
||||||
Contexts map[string]string
|
Contexts map[string]string
|
||||||
CherryPickedShas []string
|
CherryPickedCommits []*commands.Commit
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewGui builds a new gui handler
|
// NewGui builds a new gui handler
|
||||||
func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *commands.OSCommand, tr *i18n.Localizer, config config.AppConfigurer, updater *updates.Updater) (*Gui, error) {
|
func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *commands.OSCommand, tr *i18n.Localizer, config config.AppConfigurer, updater *updates.Updater) (*Gui, error) {
|
||||||
|
|
||||||
initialState := guiState{
|
initialState := guiState{
|
||||||
Files: make([]*commands.File, 0),
|
Files: make([]*commands.File, 0),
|
||||||
PreviousView: "files",
|
PreviousView: "files",
|
||||||
Commits: make([]*commands.Commit, 0),
|
Commits: make([]*commands.Commit, 0),
|
||||||
CherryPickedShas: []string{},
|
CherryPickedCommits: make([]*commands.Commit, 0),
|
||||||
StashEntries: make([]*commands.StashEntry, 0),
|
StashEntries: make([]*commands.StashEntry, 0),
|
||||||
Platform: *oSCommand.Platform,
|
Platform: *oSCommand.Platform,
|
||||||
Panels: &panelStates{
|
Panels: &panelStates{
|
||||||
Files: &filePanelState{SelectedLine: -1},
|
Files: &filePanelState{SelectedLine: -1},
|
||||||
Branches: &branchPanelState{SelectedLine: 0},
|
Branches: &branchPanelState{SelectedLine: 0},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user