github.com/driusan/dgit@v0.0.0-20221118233547-f39f0c15edbb/git/branch.go (about)

     1  package git
     2  
     3  import (
     4  	"fmt"
     5  	"io"
     6  )
     7  
     8  type BranchOptions struct {
     9  	All    bool
    10  	Quiet  bool
    11  	Move   bool
    12  	Delete bool
    13  	Force  bool
    14  }
    15  
    16  func BranchList(c *Client, stdout io.Writer, opts BranchOptions, patterns []string) ([]Branch, error) {
    17  	branches, err := c.GetBranches()
    18  	if err != nil {
    19  		return nil, err
    20  	}
    21  	if opts.All {
    22  		rb, err := c.GetRemoteBranches()
    23  		if err != nil {
    24  			return nil, err
    25  		}
    26  		branches = append(branches, rb...)
    27  	}
    28  	if !opts.Quiet {
    29  		head := c.GetHeadBranch()
    30  		for _, b := range branches {
    31  			if head == b {
    32  				fmt.Println(" *", b.BranchName())
    33  			} else {
    34  				fmt.Println("  ", b.BranchName())
    35  			}
    36  
    37  		}
    38  	}
    39  	return branches, nil
    40  }