Documentation
¶
Index ¶
- func AddWorktree(path, branch, baseRef string) error
- func AddWorktreeFromExisting(path, branch string) error
- func AddWorktreeFromRemote(path, localBranch, remoteBranch string) error
- func BranchExists(name string) bool
- func CurrentBranch() (string, error)
- func CurrentBranchIn(dir string) (string, error)
- func DeleteBranch(name string) error
- func DeleteRemoteBranch(remote, branch string) error
- func DiffNameOnly(ref1, ref2 string) ([]string, error)
- func DiffNameOnlyIn(dir, ref1, ref2 string) ([]string, error)
- func Fetch(remote string, refs ...string) error
- func FetchAll(remote string) error
- func FetchPrune()
- func GitDir() (string, error)
- func HasChanges() bool
- func HasChangesIn(dir string) bool
- func IsInsideWorkTree() bool
- func IsRebaseInProgress() (bool, error)
- func LastCommitAge(dir string) string
- func LastCommitDaysAgo(dir string) int
- func MainWorktree() (string, error)
- func MergeFF(ref string) (string, error)
- func MergeFFIn(dir, ref string) error
- func MoveWorktree(oldPath, newPath string) error
- func ParentDir() (string, error)
- func PotentialConflicts(baseRef string) ([]string, error)
- func PruneWorktrees()
- func PushForceWithLease() error
- func PushSetUpstream(remote string) error
- func ReadStateFile(name string) (string, error)
- func Rebase(onto string) error
- func RebaseAbort() error
- func RebaseAbortIn(dir string)
- func RebaseContinue() error
- func RebaseIn(dir, onto string) error
- func RemoteBranchExists(name string) bool
- func RemoveStateFile(name string)
- func RemoveWorktree(path string) error
- func RenameBranch(oldName, newName string) error
- func RepoName() (string, error)
- func ResolveBranch(name, remote string) (ref string, isRemote bool, err error)
- func RevParseHead() (string, error)
- func RevParseHeadIn(dir string) (string, error)
- func Run(args ...string) (string, error)
- func RunIn(dir string, args ...string) (string, error)
- func RunPassthrough(args ...string) error
- func RunPassthroughIn(dir string, args ...string) error
- func RunSilent(args ...string) error
- func RunSilentIn(dir string, args ...string) error
- func SaveStateFile(name, content string) error
- func StashPop() error
- func StashPush(message string) error
- func StateFileExists(name string) bool
- func StatusShort() (string, error)
- func TopLevel() (string, error)
- func UnpushedCountIn(dir string) int
- func Upstream() string
- func Username() (string, error)
- type AheadBehind
- type FileChange
- type Worktree
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddWorktree ¶
AddWorktree creates a new worktree with a new branch from a base ref.
func AddWorktreeFromExisting ¶
AddWorktreeFromExisting creates a worktree checking out an existing branch.
func AddWorktreeFromRemote ¶
AddWorktreeFromRemote creates a worktree with a local tracking branch from a remote.
func BranchExists ¶
BranchExists checks if a local branch exists.
func CurrentBranch ¶
CurrentBranch returns the current branch name, or "" for detached HEAD.
func CurrentBranchIn ¶
CurrentBranchIn returns the current branch for a specific worktree.
func DeleteRemoteBranch ¶
DeleteRemoteBranch deletes a branch on the remote.
func DiffNameOnly ¶ added in v1.14.0
DiffNameOnly returns filenames that changed between two refs.
func DiffNameOnlyIn ¶ added in v1.14.0
DiffNameOnlyIn returns filenames that changed between two refs in a directory.
func HasChanges ¶
func HasChanges() bool
HasChanges returns true if the working tree has uncommitted changes.
func HasChangesIn ¶
HasChangesIn returns true if a specific worktree has uncommitted changes.
func IsInsideWorkTree ¶
func IsInsideWorkTree() bool
IsInsideWorkTree returns true if the current directory is inside a git repo.
func IsRebaseInProgress ¶
IsRebaseInProgress checks if a rebase is currently active.
func LastCommitAge ¶
LastCommitAge returns the relative age of the last commit (e.g., "2 hours ago").
func LastCommitDaysAgo ¶
LastCommitDaysAgo returns the number of days since the last commit in a directory. Returns -1 if the age cannot be determined.
func MainWorktree ¶
MainWorktree returns the path of the main (first) worktree.
func MoveWorktree ¶
MoveWorktree moves a worktree to a new path.
func ParentDir ¶
ParentDir returns the parent directory of the main worktree (where sibling worktrees are created).
func PotentialConflicts ¶
PotentialConflicts returns files modified on both HEAD and baseRef since they diverged. These files could potentially conflict during a rebase.
func PushSetUpstream ¶
PushSetUpstream pushes and sets the upstream.
func ReadStateFile ¶
ReadStateFile reads a state file from the git dir.
func RebaseAbortIn ¶
func RebaseAbortIn(dir string)
RebaseAbortIn aborts a rebase in a specific directory.
func RemoteBranchExists ¶
RemoteBranchExists checks if a remote branch exists (e.g., "origin/feature").
func RemoveStateFile ¶
func RemoveStateFile(name string)
RemoveStateFile deletes a state file. Errors are ignored since leftover state files in .git/ are harmless.
func RemoveWorktree ¶
RemoveWorktree removes a worktree (force). After removal, cleans up the parent directory if it's empty.
func RenameBranch ¶
RenameBranch renames a local branch.
func RepoName ¶
RepoName returns the basename of the main worktree (the true repo name). Uses MainWorktree() rather than --show-toplevel, which would return the linked worktree's directory name when called from inside one.
func ResolveBranch ¶
ResolveBranch tries to find a branch ref in order: local, remotes/<name>, remotes/origin/<name>. Returns the ref, whether it's remote, and any error.
func RevParseHead ¶ added in v1.14.0
RevParseHead returns the current HEAD commit hash.
func RevParseHeadIn ¶ added in v1.14.0
RevParseHeadIn returns the HEAD commit hash in a specific directory.
func Run ¶
Run executes a git command and returns its trimmed stdout. If the command fails, the error includes stderr.
func RunPassthrough ¶
RunPassthrough executes a git command with stdout/stderr connected to the terminal. Used for commands where the user needs to see real-time output (rebase, push, etc.).
func RunPassthroughIn ¶
RunPassthroughIn executes a git command in a directory with passthrough I/O.
func RunSilent ¶
RunSilent executes a git command and discards all output. Returns only whether it succeeded.
func RunSilentIn ¶
RunSilentIn executes a git command in a directory silently.
func SaveStateFile ¶
SaveStateFile writes the rebase state to a file in the git dir.
func StateFileExists ¶
StateFileExists checks if a state file exists.
func StatusShort ¶
StatusShort returns the short status output for display.
func UnpushedCountIn ¶
UnpushedCountIn returns the number of commits ahead of the upstream.
Types ¶
type AheadBehind ¶
AheadBehind returns how many commits a branch is ahead/behind a ref.
func GetAheadBehind ¶
func GetAheadBehind(remoteRef string) (AheadBehind, error)
GetAheadBehind computes ahead/behind between HEAD and a remote ref.
func GetAheadBehindIn ¶
func GetAheadBehindIn(dir, remoteRef string) (AheadBehind, error)
GetAheadBehindIn computes ahead/behind for a specific worktree.
type FileChange ¶
type FileChange struct {
Status string // Two-character status (e.g., "M ", " M", "??", "R ")
Path string
// For renames: original path
OldPath string
}
FileChange represents a single file change from git status --porcelain.
func ParsePorcelainOutput ¶
func ParsePorcelainOutput(out string) []FileChange
ParsePorcelainOutput parses the output of `git status --porcelain` into FileChanges.
func StatusPorcelain ¶
func StatusPorcelain() ([]FileChange, error)
StatusPorcelain returns parsed file changes.
func StatusPorcelainIn ¶
func StatusPorcelainIn(dir string) ([]FileChange, error)
StatusPorcelainIn returns parsed file changes for a specific directory. Uses -uall to list individual files inside untracked directories, rather than collapsing them into a single directory entry.
func (FileChange) IsRename ¶
func (f FileChange) IsRename() bool
IsRename returns true if this change is a rename.
type Worktree ¶
Worktree represents a git worktree entry.
func ListWorktrees ¶
ListWorktrees returns all worktrees from `git worktree list --porcelain`.
func ParseWorktreeList ¶
ParseWorktreeList parses the porcelain output of `git worktree list`.