1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-06 23:46:13 +02:00

move remotes and remote branches

This commit is contained in:
Jesse Duffield 2020-09-29 18:41:06 +10:00
parent e849ca3372
commit eda4619a4f
9 changed files with 23 additions and 21 deletions

View File

@ -5,9 +5,11 @@ import (
"regexp" "regexp"
"sort" "sort"
"strings" "strings"
"github.com/jesseduffield/lazygit/pkg/models"
) )
func (c *GitCommand) GetRemotes() ([]*Remote, error) { func (c *GitCommand) GetRemotes() ([]*models.Remote, error) {
// get remote branches // get remote branches
unescaped := "git branch -r" unescaped := "git branch -r"
remoteBranchesStr, err := c.OSCommand.RunCommandWithOutput(unescaped) remoteBranchesStr, err := c.OSCommand.RunCommandWithOutput(unescaped)
@ -21,21 +23,21 @@ func (c *GitCommand) GetRemotes() ([]*Remote, error) {
} }
// first step is to get our remotes from go-git // first step is to get our remotes from go-git
remotes := make([]*Remote, len(goGitRemotes)) remotes := make([]*models.Remote, len(goGitRemotes))
for i, goGitRemote := range goGitRemotes { for i, goGitRemote := range goGitRemotes {
remoteName := goGitRemote.Config().Name remoteName := goGitRemote.Config().Name
re := regexp.MustCompile(fmt.Sprintf(`%s\/([\S]+)`, remoteName)) re := regexp.MustCompile(fmt.Sprintf(`%s\/([\S]+)`, remoteName))
matches := re.FindAllStringSubmatch(remoteBranchesStr, -1) matches := re.FindAllStringSubmatch(remoteBranchesStr, -1)
branches := make([]*RemoteBranch, len(matches)) branches := make([]*models.RemoteBranch, len(matches))
for j, match := range matches { for j, match := range matches {
branches[j] = &RemoteBranch{ branches[j] = &models.RemoteBranch{
Name: match[1], Name: match[1],
RemoteName: remoteName, RemoteName: remoteName,
} }
} }
remotes[i] = &Remote{ remotes[i] = &models.Remote{
Name: goGitRemote.Config().Name, Name: goGitRemote.Config().Name,
Urls: goGitRemote.Config().URLs, Urls: goGitRemote.Config().URLs,
Branches: branches, Branches: branches,

View File

@ -19,8 +19,8 @@ type CustomCommandObjects struct {
SelectedSubCommit *models.Commit SelectedSubCommit *models.Commit
SelectedFile *commands.File SelectedFile *commands.File
SelectedLocalBranch *models.Branch SelectedLocalBranch *models.Branch
SelectedRemoteBranch *commands.RemoteBranch SelectedRemoteBranch *models.RemoteBranch
SelectedRemote *commands.Remote SelectedRemote *models.Remote
SelectedTag *models.Tag SelectedTag *models.Tag
SelectedStashEntry *commands.StashEntry SelectedStashEntry *commands.StashEntry
SelectedCommitFile *commands.CommitFile SelectedCommitFile *commands.CommitFile

View File

@ -286,8 +286,8 @@ type guiState struct {
// one and the same // one and the same
ReflogCommits []*models.Commit ReflogCommits []*models.Commit
SubCommits []*models.Commit SubCommits []*models.Commit
Remotes []*commands.Remote Remotes []*models.Remote
RemoteBranches []*commands.RemoteBranch RemoteBranches []*models.RemoteBranch
Tags []*models.Tag Tags []*models.Tag
MenuItems []*menuItem MenuItems []*menuItem
Updating bool Updating bool

View File

@ -1,12 +1,12 @@
package presentation package presentation
import ( import (
"github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/models"
"github.com/jesseduffield/lazygit/pkg/theme" "github.com/jesseduffield/lazygit/pkg/theme"
"github.com/jesseduffield/lazygit/pkg/utils" "github.com/jesseduffield/lazygit/pkg/utils"
) )
func GetRemoteBranchListDisplayStrings(branches []*commands.RemoteBranch, diffName string) [][]string { func GetRemoteBranchListDisplayStrings(branches []*models.RemoteBranch, diffName string) [][]string {
lines := make([][]string, len(branches)) lines := make([][]string, len(branches))
for i := range branches { for i := range branches {
@ -18,7 +18,7 @@ func GetRemoteBranchListDisplayStrings(branches []*commands.RemoteBranch, diffNa
} }
// getRemoteBranchDisplayStrings returns the display string of branch // getRemoteBranchDisplayStrings returns the display string of branch
func getRemoteBranchDisplayStrings(b *commands.RemoteBranch, diffed bool) []string { func getRemoteBranchDisplayStrings(b *models.RemoteBranch, diffed bool) []string {
nameColorAttr := GetBranchColor(b.Name) nameColorAttr := GetBranchColor(b.Name)
if diffed { if diffed {
nameColorAttr = theme.DiffTerminalColor nameColorAttr = theme.DiffTerminalColor

View File

@ -4,12 +4,12 @@ import (
"fmt" "fmt"
"github.com/fatih/color" "github.com/fatih/color"
"github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/models"
"github.com/jesseduffield/lazygit/pkg/theme" "github.com/jesseduffield/lazygit/pkg/theme"
"github.com/jesseduffield/lazygit/pkg/utils" "github.com/jesseduffield/lazygit/pkg/utils"
) )
func GetRemoteListDisplayStrings(remotes []*commands.Remote, diffName string) [][]string { func GetRemoteListDisplayStrings(remotes []*models.Remote, diffName string) [][]string {
lines := make([][]string, len(remotes)) lines := make([][]string, len(remotes))
for i := range remotes { for i := range remotes {
@ -21,7 +21,7 @@ func GetRemoteListDisplayStrings(remotes []*commands.Remote, diffName string) []
} }
// getRemoteDisplayStrings returns the display string of branch // getRemoteDisplayStrings returns the display string of branch
func getRemoteDisplayStrings(r *commands.Remote, diffed bool) []string { func getRemoteDisplayStrings(r *models.Remote, diffed bool) []string {
branchCount := len(r.Branches) branchCount := len(r.Branches)
nameColorAttr := theme.DefaultTextColor nameColorAttr := theme.DefaultTextColor

View File

@ -4,12 +4,12 @@ import (
"fmt" "fmt"
"github.com/jesseduffield/gocui" "github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/models"
) )
// list panel functions // list panel functions
func (gui *Gui) getSelectedRemoteBranch() *commands.RemoteBranch { func (gui *Gui) getSelectedRemoteBranch() *models.RemoteBranch {
selectedLine := gui.State.Panels.RemoteBranches.SelectedLineIdx selectedLine := gui.State.Panels.RemoteBranches.SelectedLineIdx
if selectedLine == -1 || len(gui.State.RemoteBranches) == 0 { if selectedLine == -1 || len(gui.State.RemoteBranches) == 0 {
return nil return nil

View File

@ -6,13 +6,13 @@ 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/models"
"github.com/jesseduffield/lazygit/pkg/utils" "github.com/jesseduffield/lazygit/pkg/utils"
) )
// list panel functions // list panel functions
func (gui *Gui) getSelectedRemote() *commands.Remote { func (gui *Gui) getSelectedRemote() *models.Remote {
selectedLine := gui.State.Panels.Remotes.SelectedLineIdx selectedLine := gui.State.Panels.Remotes.SelectedLineIdx
if selectedLine == -1 || len(gui.State.Remotes) == 0 { if selectedLine == -1 || len(gui.State.Remotes) == 0 {
return nil return nil

View File

@ -1,4 +1,4 @@
package commands package models
// Remote : A git remote // Remote : A git remote
type Remote struct { type Remote struct {

View File

@ -1,4 +1,4 @@
package commands package models
// Remote Branch : A git remote branch // Remote Branch : A git remote branch
type RemoteBranch struct { type RemoteBranch struct {