Skip to content

Commit

Permalink
(feat): add flag option for showing remote branches
Browse files Browse the repository at this point in the history
  • Loading branch information
a-camarillo committed Apr 6, 2024
1 parent a5e5f54 commit 0de12b5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
16 changes: 14 additions & 2 deletions cmd/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ func NewGitRepositoryFromString(s string) (*GitRepository, error) {

// NewReferences accepts a GitRepository and returns a pointer to a
// References object
func NewReferences(r *GitRepository) (*References, error) {
func NewReferences(g *GitRepository) (*References, error) {

refs, err := r.Repository.References()
refs, err := g.Repository.References()
if err != nil {
return nil, err
}
Expand All @@ -49,6 +49,18 @@ func NewReferences(r *GitRepository) (*References, error) {
func (r *References) GetReferenceNames() ([]string, error) {
var refNames []string

r.Refs.ForEach(func(ref *plumbing.Reference) error {
if ref.Type() == plumbing.HashReference && !ref.Name().IsTag() &&!ref.Name().IsRemote() {
refNames = append(refNames, ref.Name().Short())
}
return nil
})
return refNames, nil
}

func (r *References) GetReferenceNamesWithRemotes() ([]string, error) {
var refNames []string

r.Refs.ForEach(func(ref *plumbing.Reference) error {
if ref.Type() == plumbing.HashReference && !ref.Name().IsTag() {
refNames = append(refNames, ref.Name().Short())
Expand Down
21 changes: 11 additions & 10 deletions cmd/broom.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ func InitializeMenu() {

app := tview.NewApplication()

// if len(os.Args) > 1 {
// path = os.Args[1]
// } else {
// path = "."
// }
path = pwd
repo, err := NewGitRepositoryFromString(path)
if err != nil {
Expand Down Expand Up @@ -71,11 +66,17 @@ func InitializeMenu() {
SetText("Are you sure you want to delete these branches?").
SetBackgroundColor(tcell.ColorBlack).
AddButtons([]string{"Yes", "No"})

refNames, _ := refs.GetReferenceNames()
for _, i := range refNames {
branchList.AddItem(i, "", 0, nil)
}
if !Remotes {
refNames, _ := refs.GetReferenceNames()
for _, i := range refNames {
branchList.AddItem(i, "", 0, nil)
}
} else {
refNames, _ := refs.GetReferenceNamesWithRemotes()
for _, i := range refNames {
branchList.AddItem(i, "", 0, nil)
}
}

flex := tview.NewFlex().SetDirection(tview.FlexRow).
AddItem(tview.NewFlex().
Expand Down
4 changes: 4 additions & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import (
"github.com/spf13/cobra"
)

var Remotes bool

func init() {
rootCmd.AddCommand(runCmd)
runCmd.Flags().BoolVar(&Remotes,"with-remotes",false,"Additionally show remote branches")
}

var runCmd = &cobra.Command{
Expand All @@ -17,3 +20,4 @@ var runCmd = &cobra.Command{
InitializeMenu()
},
}

0 comments on commit 0de12b5

Please sign in to comment.