gitcmd

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package gitcmd provides functions for interacting with the git command-line tool.

Index

Constants

This section is empty.

Variables

View Source
var AreChangesIncluded areChangesIncludedFunc = areChangesIncludedImpl

AreChangesIncluded is a variable holding the implementation, allowing mocking. It checks if all changes in headBranch are included in upstreamBranch using 'git cherry -v'.

Functions

func DeleteBranches

func DeleteBranches(ctx context.Context, branches []BranchToDelete, dryRun bool) []types.DeleteResult

DeleteBranches attempts to delete the specified local and remote branches. It takes a slice of BranchToDelete structs and returns a slice of DeleteResult detailing the outcome of each attempt.

func FetchAndPrune

func FetchAndPrune(ctx context.Context, remoteName string) error

FetchAndPrune runs 'git fetch <remote> --prune' to update local refs and remove any stale remote-tracking branches. It returns an error if the command fails, but the plan suggests treating this as a warning rather than a fatal error in the main application flow.

func GetAllLocalBranchInfo

func GetAllLocalBranchInfo(ctx context.Context) ([]types.BranchInfo, error)

GetAllLocalBranchInfo retrieves information about all local branches.

func GetCurrentBranchName

func GetCurrentBranchName(ctx context.Context) (string, error)

GetCurrentBranchName retrieves the name of the currently checked-out branch. It returns an empty string if HEAD is detached or if an error occurs.

func GetMainBranchHash

func GetMainBranchHash(ctx context.Context, branchName string) (string, error)

GetMainBranchHash retrieves the commit hash for the specified branch name.

func GetMergedBranches

func GetMergedBranches(ctx context.Context, targetHash string) (map[string]bool, error)

GetMergedBranches returns a map of branch names that are fully merged into the specified commit hash. The map value is always true.

func IsInGitRepo

func IsInGitRepo(ctx context.Context) (bool, error)

IsInGitRepo checks if the current directory is within a Git working tree.

func RunGitCommand

func RunGitCommand(ctx context.Context, args ...string) (string, error)

RunGitCommand is a convenience wrapper that uses the package-level Runner. All internal gitcmd functions should use this instead of calling runGitCommandReal directly.

Types

type BranchToDelete

type BranchToDelete struct {
	Name     string
	IsRemote bool
	Remote   string // Only used if IsRemote is true
	IsMerged bool   // Used to determine -d vs -D for local delete
	Hash     string // Potentially useful for logging/confirmation
}

BranchToDelete holds information needed to delete a specific branch.

type GitRunner

type GitRunner func(ctx context.Context, args ...string) (stdout string, err error)

GitRunner defines the function signature for executing git commands. This allows mocking the actual git execution during tests.

var Runner GitRunner = runGitCommandReal

Runner is the package-level variable holding the function used to run git commands. It defaults to the real implementation but can be swapped out in tests.

Jump to

Keyboard shortcuts

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