summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-08-22 11:57:44 +1000
committerJesse Duffield <jessedduffield@gmail.com>2020-08-23 14:29:18 +1000
commit442f6cd854d972c3797ca203c8de6943fe81d2ca (patch)
treebd4b60dce12233f2bc15111efd7c473b58005b39
parentc2b154acad4e1040bdc0e09cf44733ccd877923b (diff)
more cherry picking stuff, mostly around the reflog
-rw-r--r--pkg/gui/cherry_picking.go12
-rw-r--r--pkg/gui/commits_panel.go5
-rw-r--r--pkg/gui/keybindings.go37
-rw-r--r--pkg/gui/list_context.go6
-rw-r--r--pkg/gui/presentation/reflog_commits.go28
5 files changed, 67 insertions, 21 deletions
diff --git a/pkg/gui/cherry_picking.go b/pkg/gui/cherry_picking.go
index bd0ee5007..e683d0f3f 100644
--- a/pkg/gui/cherry_picking.go
+++ b/pkg/gui/cherry_picking.go
@@ -55,7 +55,7 @@ func (gui *Gui) handleCopyCommit() error {
return context.HandleRender()
}
-func (gui *Gui) CherryPickedCommitShaMap() map[string]bool {
+func (gui *Gui) cherryPickedCommitShaMap() map[string]bool {
commitShaMap := map[string]bool{}
for _, commit := range gui.State.Modes.CherryPicking.CherryPickedCommits {
commitShaMap[commit.Sha] = true
@@ -84,7 +84,7 @@ func (gui *Gui) commitsListForContext() []*commands.Commit {
}
func (gui *Gui) addCommitToCherryPickedCommits(index int) {
- commitShaMap := gui.CherryPickedCommitShaMap()
+ commitShaMap := gui.cherryPickedCommitShaMap()
commitsList := gui.commitsListForContext()
commitShaMap[commitsList[index].Sha] = true
@@ -110,7 +110,9 @@ func (gui *Gui) handleCopyCommitRange() error {
return nil
}
- gui.resetCherryPickingIfNecessary(context)
+ if err := gui.resetCherryPickingIfNecessary(context); err != nil {
+ return err
+ }
commit, ok := context.SelectedItem().(*commands.Commit)
if !ok {
@@ -120,7 +122,7 @@ func (gui *Gui) handleCopyCommitRange() error {
return nil
}
- commitShaMap := gui.CherryPickedCommitShaMap()
+ commitShaMap := gui.cherryPickedCommitShaMap()
// find the last commit that is copied that's above our position
// if there are none, startIndex = 0
@@ -135,7 +137,7 @@ func (gui *Gui) handleCopyCommitRange() error {
gui.addCommitToCherryPickedCommits(index)
}
- return gui.Contexts.BranchCommits.Context.HandleRender()
+ return context.HandleRender()
}
// HandlePasteCommits begins a cherry-pick rebase with the commits the user has copied
diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go
index d74eec550..e1bd262bf 100644
--- a/pkg/gui/commits_panel.go
+++ b/pkg/gui/commits_panel.go
@@ -554,11 +554,6 @@ func (gui *Gui) handleOpenSearchForCommitsPanel(g *gocui.Gui, v *gocui.View) err
return gui.handleOpenSearch(gui.g, v)
}
-func (gui *Gui) handleResetCherryPick(g *gocui.Gui, v *gocui.View) error {
- gui.State.Modes.CherryPicking.CherryPickedCommits = []*commands.Commit{}
- return gui.Contexts.BranchCommits.Context.HandleRender()
-}
-
func (gui *Gui) handleGotoBottomForCommitsPanel(g *gocui.Gui, v *gocui.View) error {
// we usually lazyload these commits but now that we're searching we need to load them now
if gui.State.Panels.Commits.LimitCommits {
diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go
index f9d6a777f..9e377690c 100644
--- a/pkg/gui/keybindings.go
+++ b/pkg/gui/keybindings.go
@@ -815,7 +815,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
ViewName: "commits",
Contexts: []string{BRANCH_COMMITS_CONTEXT_KEY},
Key: gui.getKey("commits.resetCherryPick"),
- Handler: gui.handleResetCherryPick,
+ Handler: gui.wrappedHandler(gui.exitCherryPickingMode),
Description: gui.Tr.SLocalize("resetCherryPick"),
},
{
@@ -840,6 +840,27 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Description: gui.Tr.SLocalize("viewResetOptions"),
},
{
+ ViewName: "commits",
+ Contexts: []string{REFLOG_COMMITS_CONTEXT_KEY},
+ Key: gui.getKey("commits.cherryPickCopy"),
+ Handler: gui.wrappedHandler(gui.handleCopyCommit),
+ Description: gui.Tr.SLocalize("cherryPickCopy"),
+ },
+ {
+ ViewName: "commits",
+ Contexts: []string{REFLOG_COMMITS_CONTEXT_KEY},
+ Key: gui.getKey("commits.cherryPickCopyRange"),
+ Handler: gui.wrappedHandler(gui.handleCopyCommitRange),
+ Description: gui.Tr.SLocalize("cherryPickCopyRange"),
+ },
+ {
+ ViewName: "commits",
+ Contexts: []string{REFLOG_COMMITS_CONTEXT_KEY},
+ Key: gui.getKey("commits.resetCherryPick"),
+ Handler: gui.wrappedHandler(gui.exitCherryPickingMode),
+ Description: gui.Tr.SLocalize("resetCherryPick"),
+ },
+ {
ViewName: "branches",
Contexts: []string{SUB_COMMITS_CONTEXT_KEY},
Key: gui.getKey("universal.goInto"),
@@ -875,6 +896,20 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Description: gui.Tr.SLocalize("cherryPickCopy"),
},
{
+ ViewName: "branches",
+ Contexts: []string{SUB_COMMITS_CONTEXT_KEY},
+ Key: gui.getKey("commits.cherryPickCopyRange"),
+ Handler: gui.wrappedHandler(gui.handleCopyCommitRange),
+ Description: gui.Tr.SLocalize("cherryPickCopyRange"),
+ },
+ {
+ ViewName: "branches",
+ Contexts: []string{SUB_COMMITS_CONTEXT_KEY},
+ Key: gui.getKey("commits.resetCherryPick"),
+ Handler: gui.wrappedHandler(gui.exitCherryPickingMode),
+ Description: gui.Tr.SLocalize("resetCherryPick"),
+ },
+ {
ViewName: "stash",
Key: gui.getKey("universal.goInto"),
Handler: gui.wrappedHandler(gui.handleViewStashFiles),
diff --git a/pkg/gui/list_context.go b/pkg/gui/list_context.go
index f97af7675..199f0b5bb 100644
--- a/pkg/gui/list_context.go
+++ b/pkg/gui/list_context.go
@@ -367,7 +367,7 @@ func (gui *Gui) branchCommitsListContext() *ListContext {
RendersToMainView: true,
Kind: SIDE_CONTEXT,
GetDisplayStrings: func() [][]string {
- return presentation.GetCommitListDisplayStrings(gui.State.Commits, gui.State.ScreenMode != SCREEN_NORMAL, gui.CherryPickedCommitShaMap(), gui.State.Modes.Diffing.Ref)
+ return presentation.GetCommitListDisplayStrings(gui.State.Commits, gui.State.ScreenMode != SCREEN_NORMAL, gui.cherryPickedCommitShaMap(), gui.State.Modes.Diffing.Ref)
},
Contains: CONTAINS_FILES,
SelectedItem: func() ListItem { return gui.getSelectedLocalCommit() },
@@ -385,7 +385,7 @@ func (gui *Gui) reflogCommitsListContext() *ListContext {
RendersToMainView: true,
Kind: SIDE_CONTEXT,
GetDisplayStrings: func() [][]string {
- return presentation.GetReflogCommitListDisplayStrings(gui.State.FilteredReflogCommits, gui.State.ScreenMode != SCREEN_NORMAL, gui.State.Modes.Diffing.Ref)
+ return presentation.GetReflogCommitListDisplayStrings(gui.State.FilteredReflogCommits, gui.State.ScreenMode != SCREEN_NORMAL, gui.cherryPickedCommitShaMap(), gui.State.Modes.Diffing.Ref)
},
Contains: CONTAINS_FILES,
SelectedItem: func() ListItem { return gui.getSelectedReflogCommit() },
@@ -404,7 +404,7 @@ func (gui *Gui) subCommitsListContext() *ListContext {
Kind: SIDE_CONTEXT,
GetDisplayStrings: func() [][]string {
gui.Log.Warn("getting display strings for sub commits")
- return presentation.GetCommitListDisplayStrings(gui.State.SubCommits, gui.State.ScreenMode != SCREEN_NORMAL, gui.CherryPickedCommitShaMap(), gui.State.Modes.Diffing.Ref)
+ return presentation.GetCommitListDisplayStrings(gui.State.SubCommits, gui.State.ScreenMode != SCREEN_NORMAL, gui.cherryPickedCommitShaMap(), gui.State.Modes.Diffing.Ref)
},
Contains: CONTAINS_COMMITS,
SelectedItem: func() ListItem { return gui.getSelectedSubCommit() },
diff --git a/pkg/gui/presentation/reflog_commits.go b/pkg/gui/presentation/reflog_commits.go
index cf3765b1c..b7530e2b9 100644
--- a/pkg/gui/presentation/reflog_commits.go
+++ b/pkg/gui/presentation/reflog_commits.go
@@ -7,10 +7,10 @@ import (
"github.com/jesseduffield/lazygit/pkg/utils"
)
-func GetReflogCommitListDisplayStrings(commits []*commands.Commit, fullDescription bool, diffName string) [][]string {
+func GetReflogCommitListDisplayStrings(commits []*commands.Commit, fullDescription bool, cherryPickedCommitShaMap map[string]bool, diffName string) [][]string {
lines := make([][]string, len(commits))
- var displayFunc func(*commands.Commit, bool) []string
+ var displayFunc func(*commands.Commit, map[string]bool, bool) []string
if fullDescription {
displayFunc = getFullDescriptionDisplayStringsForReflogCommit
} else {
@@ -19,27 +19,41 @@ func GetReflogCommitListDisplayStrings(commits []*commands.Commit, fullDescripti
for i := range commits {
diffed := commits[i].Sha == diffName
- lines[i] = displayFunc(commits[i], diffed)
+ lines[i] = displayFunc(commits[i], cherryPickedCommitShaMap, diffed)
}
return lines
}
-func getFullDescriptionDisplayStringsForReflogCommit(c *commands.Commit, diffed bool) []string {
+func coloredReflogSha(c *commands.Commit, cherryPickedCommitShaMap map[string]bool) string {
+ var shaColor *color.Color
+ if cherryPickedCommitShaMap[c.Sha] {
+ shaColor = color.New(color.FgCyan, color.BgBlue)
+ } else {
+ shaColor = color.New(color.FgBlue)
+ }
+
+ return shaColor.Sprint(c.ShortSha())
+}
+
+func getFullDescriptionDisplayStringsForReflogCommit(c *commands.Commit, cherryPickedCommitShaMap map[string]bool, diffed bool) []string {
colorAttr := theme.DefaultTextColor
if diffed {
colorAttr = theme.DiffTerminalColor
}
return []string{
- utils.ColoredString(c.ShortSha(), color.FgBlue),
+ coloredReflogSha(c, cherryPickedCommitShaMap),
utils.ColoredString(utils.UnixToDate(c.UnixTimestamp), color.FgMagenta),
utils.ColoredString(c.Name, colorAttr),
}
}
-func getDisplayStringsForReflogCommit(c *commands.Commit, diffed bool) []string {
+func getDisplayStringsForReflogCommit(c *commands.Commit, cherryPickedCommitShaMap map[string]bool, diffed bool) []string {
defaultColor := color.New(theme.DefaultTextColor)
- return []string{utils.ColoredString(c.ShortSha(), color.FgBlue), defaultColor.Sprint(c.Name)}
+ return []string{
+ coloredReflogSha(c, cherryPickedCommitShaMap),
+ defaultColor.Sprint(c.Name),
+ }
}