From eda4619a4f05b6720d091b31e60515f7289b9a47 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Tue, 29 Sep 2020 18:41:06 +1000 Subject: [PATCH] move remotes and remote branches --- pkg/commands/loading_remotes.go | 12 +++++++----- pkg/gui/custom_commands.go | 4 ++-- pkg/gui/gui.go | 4 ++-- pkg/gui/presentation/remote_branches.go | 6 +++--- pkg/gui/presentation/remotes.go | 6 +++--- pkg/gui/remote_branches_panel.go | 4 ++-- pkg/gui/remotes_panel.go | 4 ++-- pkg/{commands => models}/remote.go | 2 +- pkg/{commands => models}/remote_branch.go | 2 +- 9 files changed, 23 insertions(+), 21 deletions(-) rename pkg/{commands => models}/remote.go (94%) rename pkg/{commands => models}/remote_branch.go (95%) diff --git a/pkg/commands/loading_remotes.go b/pkg/commands/loading_remotes.go index 26dea0f70..f1f95b52e 100644 --- a/pkg/commands/loading_remotes.go +++ b/pkg/commands/loading_remotes.go @@ -5,9 +5,11 @@ import ( "regexp" "sort" "strings" + + "github.com/jesseduffield/lazygit/pkg/models" ) -func (c *GitCommand) GetRemotes() ([]*Remote, error) { +func (c *GitCommand) GetRemotes() ([]*models.Remote, error) { // get remote branches unescaped := "git branch -r" 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 - remotes := make([]*Remote, len(goGitRemotes)) + remotes := make([]*models.Remote, len(goGitRemotes)) for i, goGitRemote := range goGitRemotes { remoteName := goGitRemote.Config().Name re := regexp.MustCompile(fmt.Sprintf(`%s\/([\S]+)`, remoteName)) matches := re.FindAllStringSubmatch(remoteBranchesStr, -1) - branches := make([]*RemoteBranch, len(matches)) + branches := make([]*models.RemoteBranch, len(matches)) for j, match := range matches { - branches[j] = &RemoteBranch{ + branches[j] = &models.RemoteBranch{ Name: match[1], RemoteName: remoteName, } } - remotes[i] = &Remote{ + remotes[i] = &models.Remote{ Name: goGitRemote.Config().Name, Urls: goGitRemote.Config().URLs, Branches: branches, diff --git a/pkg/gui/custom_commands.go b/pkg/gui/custom_commands.go index 51e929bab..c28528cac 100644 --- a/pkg/gui/custom_commands.go +++ b/pkg/gui/custom_commands.go @@ -19,8 +19,8 @@ type CustomCommandObjects struct { SelectedSubCommit *models.Commit SelectedFile *commands.File SelectedLocalBranch *models.Branch - SelectedRemoteBranch *commands.RemoteBranch - SelectedRemote *commands.Remote + SelectedRemoteBranch *models.RemoteBranch + SelectedRemote *models.Remote SelectedTag *models.Tag SelectedStashEntry *commands.StashEntry SelectedCommitFile *commands.CommitFile diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 4028e452b..8d68612de 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -286,8 +286,8 @@ type guiState struct { // one and the same ReflogCommits []*models.Commit SubCommits []*models.Commit - Remotes []*commands.Remote - RemoteBranches []*commands.RemoteBranch + Remotes []*models.Remote + RemoteBranches []*models.RemoteBranch Tags []*models.Tag MenuItems []*menuItem Updating bool diff --git a/pkg/gui/presentation/remote_branches.go b/pkg/gui/presentation/remote_branches.go index e52e6d7f3..5d1c76709 100644 --- a/pkg/gui/presentation/remote_branches.go +++ b/pkg/gui/presentation/remote_branches.go @@ -1,12 +1,12 @@ package presentation import ( - "github.com/jesseduffield/lazygit/pkg/commands" + "github.com/jesseduffield/lazygit/pkg/models" "github.com/jesseduffield/lazygit/pkg/theme" "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)) for i := range branches { @@ -18,7 +18,7 @@ func GetRemoteBranchListDisplayStrings(branches []*commands.RemoteBranch, diffNa } // 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) if diffed { nameColorAttr = theme.DiffTerminalColor diff --git a/pkg/gui/presentation/remotes.go b/pkg/gui/presentation/remotes.go index 5ad5f77c8..2c099fb18 100644 --- a/pkg/gui/presentation/remotes.go +++ b/pkg/gui/presentation/remotes.go @@ -4,12 +4,12 @@ import ( "fmt" "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/utils" ) -func GetRemoteListDisplayStrings(remotes []*commands.Remote, diffName string) [][]string { +func GetRemoteListDisplayStrings(remotes []*models.Remote, diffName string) [][]string { lines := make([][]string, len(remotes)) for i := range remotes { @@ -21,7 +21,7 @@ func GetRemoteListDisplayStrings(remotes []*commands.Remote, diffName string) [] } // 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) nameColorAttr := theme.DefaultTextColor diff --git a/pkg/gui/remote_branches_panel.go b/pkg/gui/remote_branches_panel.go index aec02b4c0..12587447a 100644 --- a/pkg/gui/remote_branches_panel.go +++ b/pkg/gui/remote_branches_panel.go @@ -4,12 +4,12 @@ import ( "fmt" "github.com/jesseduffield/gocui" - "github.com/jesseduffield/lazygit/pkg/commands" + "github.com/jesseduffield/lazygit/pkg/models" ) // list panel functions -func (gui *Gui) getSelectedRemoteBranch() *commands.RemoteBranch { +func (gui *Gui) getSelectedRemoteBranch() *models.RemoteBranch { selectedLine := gui.State.Panels.RemoteBranches.SelectedLineIdx if selectedLine == -1 || len(gui.State.RemoteBranches) == 0 { return nil diff --git a/pkg/gui/remotes_panel.go b/pkg/gui/remotes_panel.go index 102ba9e33..2d0827592 100644 --- a/pkg/gui/remotes_panel.go +++ b/pkg/gui/remotes_panel.go @@ -6,13 +6,13 @@ import ( "github.com/fatih/color" "github.com/jesseduffield/gocui" - "github.com/jesseduffield/lazygit/pkg/commands" + "github.com/jesseduffield/lazygit/pkg/models" "github.com/jesseduffield/lazygit/pkg/utils" ) // list panel functions -func (gui *Gui) getSelectedRemote() *commands.Remote { +func (gui *Gui) getSelectedRemote() *models.Remote { selectedLine := gui.State.Panels.Remotes.SelectedLineIdx if selectedLine == -1 || len(gui.State.Remotes) == 0 { return nil diff --git a/pkg/commands/remote.go b/pkg/models/remote.go similarity index 94% rename from pkg/commands/remote.go rename to pkg/models/remote.go index 1ce12963e..42ebe16ab 100644 --- a/pkg/commands/remote.go +++ b/pkg/models/remote.go @@ -1,4 +1,4 @@ -package commands +package models // Remote : A git remote type Remote struct { diff --git a/pkg/commands/remote_branch.go b/pkg/models/remote_branch.go similarity index 95% rename from pkg/commands/remote_branch.go rename to pkg/models/remote_branch.go index 36199e46f..bee004fdb 100644 --- a/pkg/commands/remote_branch.go +++ b/pkg/models/remote_branch.go @@ -1,4 +1,4 @@ -package commands +package models // Remote Branch : A git remote branch type RemoteBranch struct {