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:
@ -55,7 +55,7 @@ func (gui *Gui) handleCopyCommit() error {
|
|||||||
return context.HandleRender()
|
return context.HandleRender()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) CherryPickedCommitShaMap() map[string]bool {
|
func (gui *Gui) cherryPickedCommitShaMap() map[string]bool {
|
||||||
commitShaMap := map[string]bool{}
|
commitShaMap := map[string]bool{}
|
||||||
for _, commit := range gui.State.Modes.CherryPicking.CherryPickedCommits {
|
for _, commit := range gui.State.Modes.CherryPicking.CherryPickedCommits {
|
||||||
commitShaMap[commit.Sha] = true
|
commitShaMap[commit.Sha] = true
|
||||||
@ -84,7 +84,7 @@ func (gui *Gui) commitsListForContext() []*commands.Commit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) addCommitToCherryPickedCommits(index int) {
|
func (gui *Gui) addCommitToCherryPickedCommits(index int) {
|
||||||
commitShaMap := gui.CherryPickedCommitShaMap()
|
commitShaMap := gui.cherryPickedCommitShaMap()
|
||||||
commitsList := gui.commitsListForContext()
|
commitsList := gui.commitsListForContext()
|
||||||
commitShaMap[commitsList[index].Sha] = true
|
commitShaMap[commitsList[index].Sha] = true
|
||||||
|
|
||||||
@ -110,7 +110,9 @@ func (gui *Gui) handleCopyCommitRange() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.resetCherryPickingIfNecessary(context)
|
if err := gui.resetCherryPickingIfNecessary(context); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
commit, ok := context.SelectedItem().(*commands.Commit)
|
commit, ok := context.SelectedItem().(*commands.Commit)
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -120,7 +122,7 @@ func (gui *Gui) handleCopyCommitRange() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
commitShaMap := gui.CherryPickedCommitShaMap()
|
commitShaMap := gui.cherryPickedCommitShaMap()
|
||||||
|
|
||||||
// find the last commit that is copied that's above our position
|
// find the last commit that is copied that's above our position
|
||||||
// if there are none, startIndex = 0
|
// if there are none, startIndex = 0
|
||||||
@ -135,7 +137,7 @@ func (gui *Gui) handleCopyCommitRange() error {
|
|||||||
gui.addCommitToCherryPickedCommits(index)
|
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
|
// HandlePasteCommits begins a cherry-pick rebase with the commits the user has copied
|
||||||
|
@ -554,11 +554,6 @@ func (gui *Gui) handleOpenSearchForCommitsPanel(g *gocui.Gui, v *gocui.View) err
|
|||||||
return gui.handleOpenSearch(gui.g, v)
|
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 {
|
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
|
// we usually lazyload these commits but now that we're searching we need to load them now
|
||||||
if gui.State.Panels.Commits.LimitCommits {
|
if gui.State.Panels.Commits.LimitCommits {
|
||||||
|
@ -815,7 +815,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
ViewName: "commits",
|
ViewName: "commits",
|
||||||
Contexts: []string{BRANCH_COMMITS_CONTEXT_KEY},
|
Contexts: []string{BRANCH_COMMITS_CONTEXT_KEY},
|
||||||
Key: gui.getKey("commits.resetCherryPick"),
|
Key: gui.getKey("commits.resetCherryPick"),
|
||||||
Handler: gui.handleResetCherryPick,
|
Handler: gui.wrappedHandler(gui.exitCherryPickingMode),
|
||||||
Description: gui.Tr.SLocalize("resetCherryPick"),
|
Description: gui.Tr.SLocalize("resetCherryPick"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -839,6 +839,27 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
Handler: gui.handleCreateReflogResetMenu,
|
Handler: gui.handleCreateReflogResetMenu,
|
||||||
Description: gui.Tr.SLocalize("viewResetOptions"),
|
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",
|
ViewName: "branches",
|
||||||
Contexts: []string{SUB_COMMITS_CONTEXT_KEY},
|
Contexts: []string{SUB_COMMITS_CONTEXT_KEY},
|
||||||
@ -874,6 +895,20 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
Handler: gui.wrappedHandler(gui.handleCopyCommit),
|
Handler: gui.wrappedHandler(gui.handleCopyCommit),
|
||||||
Description: gui.Tr.SLocalize("cherryPickCopy"),
|
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",
|
ViewName: "stash",
|
||||||
Key: gui.getKey("universal.goInto"),
|
Key: gui.getKey("universal.goInto"),
|
||||||
|
@ -367,7 +367,7 @@ func (gui *Gui) branchCommitsListContext() *ListContext {
|
|||||||
RendersToMainView: true,
|
RendersToMainView: true,
|
||||||
Kind: SIDE_CONTEXT,
|
Kind: SIDE_CONTEXT,
|
||||||
GetDisplayStrings: func() [][]string {
|
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,
|
Contains: CONTAINS_FILES,
|
||||||
SelectedItem: func() ListItem { return gui.getSelectedLocalCommit() },
|
SelectedItem: func() ListItem { return gui.getSelectedLocalCommit() },
|
||||||
@ -385,7 +385,7 @@ func (gui *Gui) reflogCommitsListContext() *ListContext {
|
|||||||
RendersToMainView: true,
|
RendersToMainView: true,
|
||||||
Kind: SIDE_CONTEXT,
|
Kind: SIDE_CONTEXT,
|
||||||
GetDisplayStrings: func() [][]string {
|
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,
|
Contains: CONTAINS_FILES,
|
||||||
SelectedItem: func() ListItem { return gui.getSelectedReflogCommit() },
|
SelectedItem: func() ListItem { return gui.getSelectedReflogCommit() },
|
||||||
@ -404,7 +404,7 @@ func (gui *Gui) subCommitsListContext() *ListContext {
|
|||||||
Kind: SIDE_CONTEXT,
|
Kind: SIDE_CONTEXT,
|
||||||
GetDisplayStrings: func() [][]string {
|
GetDisplayStrings: func() [][]string {
|
||||||
gui.Log.Warn("getting display strings for sub commits")
|
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,
|
Contains: CONTAINS_COMMITS,
|
||||||
SelectedItem: func() ListItem { return gui.getSelectedSubCommit() },
|
SelectedItem: func() ListItem { return gui.getSelectedSubCommit() },
|
||||||
|
@ -7,10 +7,10 @@ import (
|
|||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"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))
|
lines := make([][]string, len(commits))
|
||||||
|
|
||||||
var displayFunc func(*commands.Commit, bool) []string
|
var displayFunc func(*commands.Commit, map[string]bool, bool) []string
|
||||||
if fullDescription {
|
if fullDescription {
|
||||||
displayFunc = getFullDescriptionDisplayStringsForReflogCommit
|
displayFunc = getFullDescriptionDisplayStringsForReflogCommit
|
||||||
} else {
|
} else {
|
||||||
@ -19,27 +19,41 @@ func GetReflogCommitListDisplayStrings(commits []*commands.Commit, fullDescripti
|
|||||||
|
|
||||||
for i := range commits {
|
for i := range commits {
|
||||||
diffed := commits[i].Sha == diffName
|
diffed := commits[i].Sha == diffName
|
||||||
lines[i] = displayFunc(commits[i], diffed)
|
lines[i] = displayFunc(commits[i], cherryPickedCommitShaMap, diffed)
|
||||||
}
|
}
|
||||||
|
|
||||||
return lines
|
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
|
colorAttr := theme.DefaultTextColor
|
||||||
if diffed {
|
if diffed {
|
||||||
colorAttr = theme.DiffTerminalColor
|
colorAttr = theme.DiffTerminalColor
|
||||||
}
|
}
|
||||||
|
|
||||||
return []string{
|
return []string{
|
||||||
utils.ColoredString(c.ShortSha(), color.FgBlue),
|
coloredReflogSha(c, cherryPickedCommitShaMap),
|
||||||
utils.ColoredString(utils.UnixToDate(c.UnixTimestamp), color.FgMagenta),
|
utils.ColoredString(utils.UnixToDate(c.UnixTimestamp), color.FgMagenta),
|
||||||
utils.ColoredString(c.Name, colorAttr),
|
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)
|
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),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user