mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-13 01:30:53 +02:00
some more standardisation for diffing
This commit is contained in:
@ -12,3 +12,7 @@ type Branch struct {
|
|||||||
UpstreamName string
|
UpstreamName string
|
||||||
Head bool
|
Head bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *Branch) RefName() string {
|
||||||
|
return b.Name
|
||||||
|
}
|
||||||
|
@ -24,3 +24,7 @@ func (c *Commit) ShortSha() string {
|
|||||||
func (c *Commit) NameWithSha() string {
|
func (c *Commit) NameWithSha() string {
|
||||||
return fmt.Sprintf("%s %s", c.Sha[:7], c.Name)
|
return fmt.Sprintf("%s %s", c.Sha[:7], c.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Commit) RefName() string {
|
||||||
|
return c.Sha
|
||||||
|
}
|
||||||
|
@ -6,3 +6,7 @@ type Remote struct {
|
|||||||
Urls []string
|
Urls []string
|
||||||
Branches []*RemoteBranch
|
Branches []*RemoteBranch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Remote) RefName() string {
|
||||||
|
return r.Name
|
||||||
|
}
|
||||||
|
@ -9,3 +9,7 @@ type RemoteBranch struct {
|
|||||||
func (r *RemoteBranch) FullName() string {
|
func (r *RemoteBranch) FullName() string {
|
||||||
return r.RemoteName + "/" + r.Name
|
return r.RemoteName + "/" + r.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *RemoteBranch) RefName() string {
|
||||||
|
return r.FullName()
|
||||||
|
}
|
||||||
|
@ -4,3 +4,7 @@ package commands
|
|||||||
type Tag struct {
|
type Tag struct {
|
||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Tag) RefName() string {
|
||||||
|
return t.Name
|
||||||
|
}
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (gui *Gui) inDiffMode() bool {
|
func (gui *Gui) inDiffMode() bool {
|
||||||
@ -42,62 +41,55 @@ func (gui *Gui) renderDiff() error {
|
|||||||
// which becomes an option when you bring up the diff menu, but when you're just
|
// which becomes an option when you bring up the diff menu, but when you're just
|
||||||
// flicking through branches it will be using the local branch name.
|
// flicking through branches it will be using the local branch name.
|
||||||
func (gui *Gui) currentDiffTerminals() []string {
|
func (gui *Gui) currentDiffTerminals() []string {
|
||||||
currentView := gui.g.CurrentView()
|
switch gui.currentContextKey() {
|
||||||
if currentView == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
names := []string{}
|
|
||||||
switch currentView.Name() {
|
|
||||||
case "files":
|
case "files":
|
||||||
// not supporting files for now
|
// not supporting files for now
|
||||||
|
case "commit-files":
|
||||||
case "commitFiles":
|
|
||||||
// not supporting commit files for now
|
// not supporting commit files for now
|
||||||
|
case "branch-commits":
|
||||||
case "commits":
|
item := gui.getSelectedCommit()
|
||||||
var commit *commands.Commit
|
if item != nil {
|
||||||
switch gui.getCommitsView().Context {
|
return []string{item.RefName()}
|
||||||
case "reflog-commits":
|
|
||||||
commit = gui.getSelectedReflogCommit()
|
|
||||||
case "branch-commits":
|
|
||||||
commit = gui.getSelectedCommit()
|
|
||||||
}
|
}
|
||||||
if commit != nil {
|
case "reflog-commits":
|
||||||
names = append(names, commit.Sha)
|
item := gui.getSelectedReflogCommit()
|
||||||
|
if item != nil {
|
||||||
|
return []string{item.RefName()}
|
||||||
}
|
}
|
||||||
case "stash":
|
case "stash":
|
||||||
entry := gui.getSelectedStashEntry()
|
item := gui.getSelectedStashEntry()
|
||||||
if entry != nil {
|
if item != nil {
|
||||||
names = append(names, entry.RefName())
|
return []string{item.RefName()}
|
||||||
}
|
}
|
||||||
case "branches":
|
|
||||||
switch gui.getBranchesView().Context {
|
case "local-branches":
|
||||||
case "local-branches":
|
branch := gui.getSelectedBranch()
|
||||||
branch := gui.getSelectedBranch()
|
if branch != nil {
|
||||||
if branch != nil {
|
names := []string{branch.RefName()}
|
||||||
names = append(names, branch.Name)
|
if branch.UpstreamName != "" {
|
||||||
if branch.UpstreamName != "" {
|
names = append(names, branch.UpstreamName)
|
||||||
names = append(names, branch.UpstreamName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "remotes":
|
|
||||||
remote := gui.getSelectedRemote()
|
|
||||||
if remote != nil {
|
|
||||||
names = append(names, remote.Name)
|
|
||||||
}
|
|
||||||
case "remote-branches":
|
|
||||||
remoteBranch := gui.getSelectedRemoteBranch()
|
|
||||||
if remoteBranch != nil {
|
|
||||||
names = append(names, remoteBranch.FullName())
|
|
||||||
}
|
|
||||||
case "tags":
|
|
||||||
tag := gui.getSelectedTag()
|
|
||||||
if tag != nil {
|
|
||||||
names = append(names, tag.Name)
|
|
||||||
}
|
}
|
||||||
|
return names
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
case "remotes":
|
||||||
|
item := gui.getSelectedRemote()
|
||||||
|
if item != nil {
|
||||||
|
return []string{item.RefName()}
|
||||||
|
}
|
||||||
|
case "remote-branches":
|
||||||
|
item := gui.getSelectedRemoteBranch()
|
||||||
|
if item != nil {
|
||||||
|
return []string{item.RefName()}
|
||||||
|
}
|
||||||
|
case "tags":
|
||||||
|
item := gui.getSelectedTag()
|
||||||
|
if item != nil {
|
||||||
|
return []string{item.RefName()}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return names
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) currentDiffTerminal() string {
|
func (gui *Gui) currentDiffTerminal() string {
|
||||||
|
@ -326,7 +326,7 @@ func (gui *Gui) stashListContext() *ListContext {
|
|||||||
func (gui *Gui) commitFilesListContext() *ListContext {
|
func (gui *Gui) commitFilesListContext() *ListContext {
|
||||||
return &ListContext{
|
return &ListContext{
|
||||||
ViewName: "commitFiles",
|
ViewName: "commitFiles",
|
||||||
ContextKey: "commitFiles",
|
ContextKey: "commit-files",
|
||||||
GetItemsLength: func() int { return len(gui.State.CommitFiles) },
|
GetItemsLength: func() int { return len(gui.State.CommitFiles) },
|
||||||
GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.CommitFiles.SelectedLine },
|
GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.CommitFiles.SelectedLine },
|
||||||
OnFocus: gui.handleCommitFileSelect,
|
OnFocus: gui.handleCommitFileSelect,
|
||||||
|
Reference in New Issue
Block a user