1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-30 03:23:08 +03:00

more cherry picking stuff, mostly around the reflog

This commit is contained in:
Jesse Duffield
2020-08-22 11:57:44 +10:00
parent c2b154acad
commit 442f6cd854
5 changed files with 67 additions and 21 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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"),
},
{
@ -839,6 +839,27 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Handler: gui.handleCreateReflogResetMenu,
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},
@ -874,6 +895,20 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Handler: gui.wrappedHandler(gui.handleCopyCommit),
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"),

View File

@ -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() },

View File

@ -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),
}
}