branch

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildRemoteBranchMap

func BuildRemoteBranchMap(remoteBranches []GitBranch) map[string]GitBranch

BuildRemoteBranchMap creates a map of branch name -> GitBranch for remote branches

func DeleteLocalBranch

func DeleteLocalBranch(name string, force bool) error

DeleteLocalBranch deletes a local branch

func DeleteRemoteBranch

func DeleteRemoteBranch(name string) error

DeleteRemoteBranch deletes a remote branch

func FetchPrune

func FetchPrune() error

FetchPrune fetches and prunes remote branches

func FormatCleanup

func FormatCleanup(result *CleanupResult, dryRun bool) string

FormatCleanup formats the cleanup result for terminal output

func FormatList

func FormatList(result *ListResult, asJSON bool) string

FormatList formats the branch list for terminal output

func FormatPRInfo

func FormatPRInfo(info *PRInfo) string

FormatPRInfo formats PR information for terminal output

func GetAheadBehind

func GetAheadBehind(branch, target string) (ahead, behind int, err error)

GetAheadBehind returns how many commits a branch is ahead/behind the target

func GetCurrentBranch

func GetCurrentBranch() (string, error)

GetCurrentBranch returns the current branch name

func GetCurrentUser

func GetCurrentUser() (string, error)

GetCurrentUser returns the current git user email

func GetDefaultBranch

func GetDefaultBranch() string

GetDefaultBranch tries to determine the default branch (main or master)

func GetTrackingBranch

func GetTrackingBranch(branch string) string

GetTrackingBranch returns the remote tracking branch for a local branch

func IsBranchMerged

func IsBranchMerged(branch, target string) bool

IsBranchMerged checks if a branch has been merged into the target branch

Types

type CleanupOptions

type CleanupOptions struct {
	DryRun        bool // Show what would be deleted without actually deleting
	IncludeStale  bool // Also delete stale branches
	IncludeOrphan bool // Also delete orphan branches
	Force         bool // Force delete even if not fully merged
}

CleanupOptions configures the cleanup operation

type CleanupResult

type CleanupResult struct {
	Deleted       []DeletedBranch
	Skipped       []SkippedBranch
	TotalDeleted  int
	LocalDeleted  int
	RemoteDeleted int
}

CleanupResult contains the result of a cleanup operation

type Config

type Config struct {
	StaleDays     int
	NamingPattern string
	AutoCleanup   bool
	Protected     []string
}

Config for branch manager

type DeletedBranch

type DeletedBranch struct {
	Name          string
	Location      Location
	Status        Status
	LocalDeleted  bool
	RemoteDeleted bool
}

DeletedBranch represents a successfully deleted branch

type GitBranch

type GitBranch struct {
	Name       string
	IsRemote   bool
	IsCurrent  bool
	CommitHash string
	CommitDate time.Time
	Author     string
	Subject    string
}

GitBranch represents raw git branch data

func GetRemoteBranchInfo

func GetRemoteBranchInfo(branchName string) (*GitBranch, error)

GetRemoteBranchInfo returns info for a specific remote branch

func ListLocalBranches

func ListLocalBranches() ([]GitBranch, error)

ListLocalBranches returns all local branches with their info

func ListRemoteBranches

func ListRemoteBranches() ([]GitBranch, error)

ListRemoteBranches returns all remote branches with their info

type Info

type Info struct {
	Name     string
	Location Location
	Status   Status

	// Local branch info
	LocalCommitDate    time.Time
	LocalCommitHash    string
	LocalAuthor        string
	LocalCommitSubject string

	// Remote branch info
	RemoteCommitDate    time.Time
	RemoteCommitHash    string
	RemoteAuthor        string
	RemoteCommitSubject string

	// Computed/derived fields
	LastCommit  time.Time // Most recent of local/remote
	AheadBehind string    // e.g., "2 ahead, 3 behind"

	// PR info
	PRNumber int
	PRStatus PRStatus
	PRTitle  string

	// Branch metadata
	IsProtected  bool
	TracksBranch string // Remote tracking branch
}

Info contains all information about a branch

type ListOptions

type ListOptions struct {
	All        bool   // Include remote branches
	Mine       bool   // Only show branches by current user
	Stale      bool   // Only show stale branches
	Merged     bool   // Only show merged branches
	Orphan     bool   // Only show orphan branches
	Author     string // Filter by author
	StaleDays  int    // Days threshold for stale (default 30)
	MainBranch string // Main branch name (default "main")
	JSON       bool   // Output as JSON
}

ListOptions configures the branch list operation

type ListResult

type ListResult struct {
	Branches       []Info
	TotalCount     int
	Summary        Summary
	HasGitHubToken bool
	CurrentBranch  string
}

ListResult contains the result of a branch list operation

type Location

type Location string

Location represents where the branch exists

const (
	LocationLocal  Location = "local"
	LocationRemote Location = "remote"
	LocationBoth   Location = "both"
)

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager handles branch operations

func NewManager

func NewManager(cfg Config) *Manager

NewManager creates a new branch manager

func (*Manager) Cleanup

func (m *Manager) Cleanup(opts CleanupOptions) (*CleanupResult, error)

Cleanup removes branches that are merged (and optionally stale/orphan)

func (*Manager) GetPRInfo

func (m *Manager) GetPRInfo(branchName string) (*PRInfo, error)

GetPRInfo returns detailed PR information for a branch

func (*Manager) List

func (m *Manager) List(opts ListOptions) (*ListResult, error)

List returns all branches matching the given options

type PRChecksInfo

type PRChecksInfo struct {
	Total   int
	Pending int
	Success int
	Failure int
	Status  string // "success", "failure", "pending"
}

PRChecksInfo contains check/CI status

type PRInfo

type PRInfo struct {
	Number      int
	Title       string
	Status      PRStatus
	URL         string
	Draft       bool
	Checks      *PRChecksInfo
	Reviews     *PRReviewsInfo
	Mergeable   bool
	BranchName  string
	BaseBranch  string
	AuthorLogin string
}

PRInfo contains detailed PR information for a branch

type PRReviewsInfo

type PRReviewsInfo struct {
	Approved         int
	ChangesRequested int
	Pending          int
}

PRReviewsInfo contains review status

type PRStatus

type PRStatus string

PRStatus represents the status of an associated PR

const (
	PRStatusNone   PRStatus = ""
	PRStatusOpen   PRStatus = "open"
	PRStatusMerged PRStatus = "merged"
	PRStatusClosed PRStatus = "closed"
)

type SkippedBranch

type SkippedBranch struct {
	Name   string
	Reason string
}

SkippedBranch represents a branch that was skipped during cleanup

type Status

type Status string

Status represents the status of a branch

const (
	StatusActive    Status = "active"
	StatusStale     Status = "stale"
	StatusMerged    Status = "merged"
	StatusProtected Status = "protected"
	StatusOrphan    Status = "orphan" // Has PR but PR was closed without merge
)

type Summary

type Summary struct {
	Total     int
	Active    int
	Stale     int
	Merged    int
	Protected int
	Orphan    int
	Local     int
	Remote    int
}

Summary contains branch statistics

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL