mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-12 21:05:48 +02:00
split RemoteBranch out from Branch
This commit is contained in:
parent
b7f2d0366b
commit
1f3e1720a3
8 changed files with 46 additions and 17 deletions
|
@ -22,7 +22,7 @@ type Branch struct {
|
||||||
|
|
||||||
// GetDisplayStrings returns the display string of branch
|
// GetDisplayStrings returns the display string of branch
|
||||||
func (b *Branch) GetDisplayStrings(isFocused bool) []string {
|
func (b *Branch) GetDisplayStrings(isFocused bool) []string {
|
||||||
displayName := utils.ColoredString(b.Name, b.GetColor())
|
displayName := utils.ColoredString(b.Name, GetBranchColor(b.Name))
|
||||||
if isFocused && b.Selected && b.Pushables != "" && b.Pullables != "" {
|
if isFocused && b.Selected && b.Pushables != "" && b.Pullables != "" {
|
||||||
displayName = fmt.Sprintf("%s ↑%s↓%s", displayName, b.Pushables, b.Pullables)
|
displayName = fmt.Sprintf("%s ↑%s↓%s", displayName, b.Pushables, b.Pullables)
|
||||||
}
|
}
|
||||||
|
@ -30,9 +30,11 @@ func (b *Branch) GetDisplayStrings(isFocused bool) []string {
|
||||||
return []string{b.Recency, displayName}
|
return []string{b.Recency, displayName}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetColor branch color
|
// GetBranchColor branch color
|
||||||
func (b *Branch) GetColor() color.Attribute {
|
func GetBranchColor(name string) color.Attribute {
|
||||||
switch b.getType() {
|
branchType := strings.Split(name, "/")[0]
|
||||||
|
|
||||||
|
switch branchType {
|
||||||
case "feature":
|
case "feature":
|
||||||
return color.FgGreen
|
return color.FgGreen
|
||||||
case "bugfix":
|
case "bugfix":
|
||||||
|
@ -43,8 +45,3 @@ func (b *Branch) GetColor() color.Attribute {
|
||||||
return theme.DefaultTextColor
|
return theme.DefaultTextColor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// expected to return feature/bugfix/hotfix or blank string
|
|
||||||
func (b *Branch) getType() string {
|
|
||||||
return strings.Split(b.Name, "/")[0]
|
|
||||||
}
|
|
||||||
|
|
|
@ -3,6 +3,8 @@ package commands
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *GitCommand) GetRemotes() ([]*Remote, error) {
|
func (c *GitCommand) GetRemotes() ([]*Remote, error) {
|
||||||
|
@ -24,9 +26,9 @@ func (c *GitCommand) GetRemotes() ([]*Remote, error) {
|
||||||
|
|
||||||
re := regexp.MustCompile(fmt.Sprintf("%s\\/(.*)", name))
|
re := regexp.MustCompile(fmt.Sprintf("%s\\/(.*)", name))
|
||||||
matches := re.FindAllStringSubmatch(remoteBranchesStr, -1)
|
matches := re.FindAllStringSubmatch(remoteBranchesStr, -1)
|
||||||
branches := make([]*Branch, len(matches))
|
branches := make([]*RemoteBranch, len(matches))
|
||||||
for j, match := range matches {
|
for j, match := range matches {
|
||||||
branches[j] = &Branch{
|
branches[j] = &RemoteBranch{
|
||||||
Name: match[1],
|
Name: match[1],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,5 +40,17 @@ func (c *GitCommand) GetRemotes() ([]*Remote, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// now lets sort our remotes by name alphabetically
|
||||||
|
sort.Slice(remotes, func(i, j int) bool {
|
||||||
|
// we want origin at the top because we'll be most likely to want it
|
||||||
|
if remotes[i].Name == "origin" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if remotes[j].Name == "origin" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return strings.ToLower(remotes[i].Name) < strings.ToLower(remotes[j].Name)
|
||||||
|
})
|
||||||
|
|
||||||
return remotes, nil
|
return remotes, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ type Remote struct {
|
||||||
Name string
|
Name string
|
||||||
Urls []string
|
Urls []string
|
||||||
Selected bool
|
Selected bool
|
||||||
Branches []*Branch
|
Branches []*RemoteBranch
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDisplayStrings returns the display string of a remote
|
// GetDisplayStrings returns the display string of a remote
|
||||||
|
|
18
pkg/commands/remote_branch.go
Normal file
18
pkg/commands/remote_branch.go
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Remote Branch : A git remote branch
|
||||||
|
type RemoteBranch struct {
|
||||||
|
Name string
|
||||||
|
Selected bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetDisplayStrings returns the display string of branch
|
||||||
|
func (b *RemoteBranch) GetDisplayStrings(isFocused bool) []string {
|
||||||
|
displayName := utils.ColoredString(b.Name, GetBranchColor(b.Name))
|
||||||
|
|
||||||
|
return []string{displayName}
|
||||||
|
}
|
|
@ -165,8 +165,8 @@ type guiState struct {
|
||||||
CommitFiles []*commands.CommitFile
|
CommitFiles []*commands.CommitFile
|
||||||
DiffEntries []*commands.Commit
|
DiffEntries []*commands.Commit
|
||||||
Remotes []*commands.Remote
|
Remotes []*commands.Remote
|
||||||
RemoteBranches []*commands.Branch // using Branch for now because they're basically the same
|
RemoteBranches []*commands.RemoteBranch
|
||||||
MenuItemCount int // can't store the actual list because it's of interface{} type
|
MenuItemCount int // can't store the actual list because it's of interface{} type
|
||||||
PreviousView string
|
PreviousView string
|
||||||
Platform commands.Platform
|
Platform commands.Platform
|
||||||
Updating bool
|
Updating bool
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
|
|
||||||
// list panel functions
|
// list panel functions
|
||||||
|
|
||||||
func (gui *Gui) getSelectedRemoteBranch() *commands.Branch {
|
func (gui *Gui) getSelectedRemoteBranch() *commands.RemoteBranch {
|
||||||
selectedLine := gui.State.Panels.RemoteBranches.SelectedLine
|
selectedLine := gui.State.Panels.RemoteBranches.SelectedLine
|
||||||
if selectedLine == -1 || len(gui.State.RemoteBranches) == 0 {
|
if selectedLine == -1 || len(gui.State.RemoteBranches) == 0 {
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -43,7 +43,6 @@ func (gui *Gui) handleRemoteSelect(g *gocui.Gui, v *gocui.View) error {
|
||||||
gui.getMainView().Title = "Remote"
|
gui.getMainView().Title = "Remote"
|
||||||
|
|
||||||
remote := gui.getSelectedRemote()
|
remote := gui.getSelectedRemote()
|
||||||
gui.focusPoint(0, gui.State.Panels.Menu.SelectedLine, gui.State.MenuItemCount, v)
|
|
||||||
if err := gui.focusPoint(0, gui.State.Panels.Remotes.SelectedLine, len(gui.State.Remotes), v); err != nil {
|
if err := gui.focusPoint(0, gui.State.Panels.Remotes.SelectedLine, len(gui.State.Remotes), v); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/commands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -34,7 +35,7 @@ func (gui *Gui) refreshStatus(g *gocui.Gui) error {
|
||||||
|
|
||||||
if len(branches) > 0 {
|
if len(branches) > 0 {
|
||||||
branch := branches[0]
|
branch := branches[0]
|
||||||
name := utils.ColoredString(branch.Name, branch.GetColor())
|
name := utils.ColoredString(branch.Name, commands.GetBranchColor(branch.Name))
|
||||||
repoName := utils.GetCurrentRepoName()
|
repoName := utils.GetCurrentRepoName()
|
||||||
status += fmt.Sprintf(" %s → %s", repoName, name)
|
status += fmt.Sprintf(" %s → %s", repoName, name)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue