Documentation
¶
Index ¶
- func BatchDeleteRemoteBranches(ctx context.Context, repoPath string, names []string) error
- func CloneForAnalysis(ctx context.Context, url, destDir string) error
- func CurrentBranch(ctx context.Context, repoPath string) string
- func DeleteLocalBranch(ctx context.Context, repoPath string, b Branch) error
- func EnrichAuthors(ctx context.Context, repoPath string, branches []Branch)
- func RemoteURL(ctx context.Context, repoPath string) string
- func ValidateRepo(ctx context.Context, repoPath string) error
- func ValidateSortField(s string) error
- func VerifyMerged(ctx context.Context, repoPath string, b Branch, fpc *FirstParentCache) error
- type Branch
- func FilterByAge(branches []Branch, olderThanDays int) []Branch
- func FilterByExcludeMergedInto(branches []Branch, patterns []string) ([]Branch, error)
- func FilterByTierHierarchy(branches []Branch, tiers [][]string) []Branch
- func FilterProtected(branches []Branch, protected []string) []Branch
- func MergedBranches(ctx context.Context, repoPath, targetBranch string, includeRemote bool, ...) ([]Branch, error)
- func MergedBranchesAnywhere(ctx context.Context, repoPath string, includeRemote bool, sortBy SortField) ([]Branch, error)
- type FirstParentCache
- type SortField
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BatchDeleteRemoteBranches ¶
BatchDeleteRemoteBranches deletes all named remote branches in a single "git push origin --delete" call, which is much faster than one call per branch. Returns an error if the push fails; on failure the caller should fall back to individual deletions to identify which specific branches could not be removed.
func CloneForAnalysis ¶
CloneForAnalysis does a treeless bare clone of url into destDir. --filter=tree:0 downloads only commit objects (no trees, no blobs) which is sufficient for all ancestry queries this tool performs (branch --contains, merge-base --is-ancestor, log --format). Much faster than blobless on large repos.
func CurrentBranch ¶
CurrentBranch returns the name of the currently checked-out branch.
func DeleteLocalBranch ¶
DeleteLocalBranch deletes a local branch using -d (safe delete). Git's own merge check provides a second safety net on top of VerifyMerged.
func EnrichAuthors ¶
EnrichAuthors populates the Author field for each branch using the first commit that is unique to that branch (via --ancestry-path from the merge-base with MergedInto). Runs in parallel using the same worker pool pattern as MergedBranchesAnywhere.
func ValidateRepo ¶
ValidateRepo checks that repoPath (or the cwd if empty) is inside a git repository.
func ValidateSortField ¶
ValidateSortField returns an error if s is not a recognised SortField.
func VerifyMerged ¶
VerifyMerged checks that b is still merged (into b.MergedInto, or anywhere if empty) without deleting it. Use this to pre-validate remote branches before a batch push.
Types ¶
type Branch ¶
type Branch struct {
Name string
IsRemote bool
LastCommit time.Time
AgeDays int
RelativeAge string
MergedInto string // the branch this was found merged into; used for deletion verification
SHA string // full 40-char tip commit hash
Author string // author of the first commit unique to this branch (optional, requires --authors)
}
Branch represents a git branch with metadata.
func FilterByAge ¶
FilterByAge returns only branches older than the given number of days.
func FilterByExcludeMergedInto ¶
FilterByExcludeMergedInto removes branches whose MergedInto field matches any of the given regex patterns. Returns an error if any pattern is invalid. Example patterns: "release/26\.0\.0", "release/.*", "hotfix/.*"
func FilterByTierHierarchy ¶
FilterByTierHierarchy enforces a branch protection hierarchy. Each element of tiers is a slice of glob patterns at that tier level (0 = highest).
- Tier 0 branches are never prunable.
- Tier N (N>0) branches are prunable only when merged into a branch at tier < N.
- Branches not in any tier are treated as an implicit lowest tier: prunable only if merged into a branch that IS in an explicit tier (any tier level). This prevents e.g. task/foo merged into task/bar from being prunable until the work reaches a named tier branch like main or release/*.
func FilterProtected ¶
FilterProtected removes protected branch names from the list. Supports glob patterns (e.g. "release/*") for consistency with --tier.
func MergedBranches ¶
func MergedBranches(ctx context.Context, repoPath, targetBranch string, includeRemote bool, sortBy SortField) ([]Branch, error)
MergedBranches returns branches that have been merged into targetBranch. Each returned branch has MergedInto set to targetBranch.
func MergedBranchesAnywhere ¶
func MergedBranchesAnywhere(ctx context.Context, repoPath string, includeRemote bool, sortBy SortField) ([]Branch, error)
MergedBranchesAnywhere returns branches whose tip commit is reachable from at least one OTHER existing branch, regardless of which branch that is. This correctly handles repos with multiple long-lived branches (hotfix/*, release/*, etc.) where feature branches may be merged back into any of them.
type FirstParentCache ¶
type FirstParentCache = firstParentCache
FirstParentCache is an opaque cache for first-parent ancestry queries. Create one with NewFirstParentCache and pass it to VerifyMerged to amortise expensive rev-list calls across many deletions.
func NewFirstParentCache ¶
func NewFirstParentCache() *FirstParentCache
NewFirstParentCache returns an empty, ready-to-use FirstParentCache.