git

package
v0.70.5 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateBranch

func CreateBranch(repoPath, branchName, fromRef string) error

func CreateBranchContext added in v0.70.5

func CreateBranchContext(ctx context.Context, repoPath, branchName, fromRef string) error

func CreateDetachedWorktree added in v0.70.5

func CreateDetachedWorktree(repoPath, worktreePath, ref string) error

func CreateDetachedWorktreeContext added in v0.70.5

func CreateDetachedWorktreeContext(ctx context.Context, repoPath, worktreePath, ref string) error

func CreateWorktree

func CreateWorktree(repoPath, worktreePath, branchName string) error

func CreateWorktreeContext added in v0.70.5

func CreateWorktreeContext(ctx context.Context, repoPath, worktreePath, branchName string) error

func DeleteBranch

func DeleteBranch(repoPath, branchName string) error

func DeleteBranchContext added in v0.70.5

func DeleteBranchContext(ctx context.Context, repoPath, branchName string) error

func DirtyFiles added in v0.3.0

func DirtyFiles(dir string) ([]string, error)

func DiscoverDefaultBranch

func DiscoverDefaultBranch(repoPath string) (string, error)

DiscoverDefaultBranch returns the preferred branch name for repoPath. In a repository without commits, it returns the symbolic initial HEAD branch even though no corresponding branch ref exists yet.

func DiscoverDefaultBranchOrHEAD added in v0.19.0

func DiscoverDefaultBranchOrHEAD(repoPath string) (string, error)

func DiscoverGitHubUsername

func DiscoverGitHubUsername(ctx context.Context, repoPath string) (string, error)

func FetchOrigin

func FetchOrigin(repoPath string) error

func FetchOriginContext added in v0.30.0

func FetchOriginContext(ctx context.Context, repoPath string) error

func FetchRemote added in v0.66.12

func FetchRemote(ctx context.Context, worktreePath string) error

FetchRemote updates remote tracking refs from origin. It prunes deleted remote branches and never rewrites local branches. It is best-effort: callers use it to keep base-branch refs fresh for the diverged-from-base count and should tolerate failures (offline, no remote).

func HasRemote added in v0.19.0

func HasRemote(dir string, name string) bool

func HasRemoteContext added in v0.70.5

func HasRemoteContext(ctx context.Context, dir string, name string) bool

func HasUncommittedChanges

func HasUncommittedChanges(dir string) (bool, error)

func IsInsideGitRepo

func IsInsideGitRepo(dir string) bool

func IsRegisteredWorktree added in v0.66.2

func IsRegisteredWorktree(repoPath, worktreePath string) bool

IsRegisteredWorktree reports whether worktreePath is registered as a worktree of the repo at repoPath. It matches even a worktree whose .git link is broken, since git still lists a stale (prunable) registration — that registration is the signal graith owns the path and may remove it during teardown (#741). It returns false when the repo is unreachable or the path is not a registered worktree (an unrelated directory, an independent repo, or an already-orphaned entry), so teardown never deletes a directory graith doesn't own. Detection is based on the stable `--porcelain` listing rather than git's error text, so it is independent of git's locale and message wording.

func ListMaintenanceRepos added in v0.42.0

func ListMaintenanceRepos(ctx context.Context) ([]string, error)

func ParseGitHubUsername

func ParseGitHubUsername(remoteURL string) (string, bool)

func PruneWorktrees added in v0.29.0

func PruneWorktrees(repoPath string) error

func PruneWorktreesContext added in v0.70.5

func PruneWorktreesContext(ctx context.Context, repoPath string) error

func RefExists

func RefExists(dir string, ref string) bool

func RefExistsContext added in v0.70.5

func RefExistsContext(ctx context.Context, dir string, ref string) bool

func RefreshReadOnlySession added in v0.70.5

func RefreshReadOnlySession(ctx context.Context, repoPath, worktreePath, branch string, fetch bool) (string, error)

func RemoveWorktree

func RemoveWorktree(repoPath, worktreePath string) error

func RepoRootFromWorktree added in v0.29.0

func RepoRootFromWorktree(worktreePath string) (string, error)

func RepoRootPath

func RepoRootPath(dir string) (string, error)

func ResolveBranchCommit added in v0.70.5

func ResolveBranchCommit(repoPath, branch string) (string, error)

ResolveBranchCommit resolves branch to a commit SHA. For ordinary branch names it prefers origin/<branch> when available, matching writable worktree creation, and falls back to the local branch. Fully-qualified refs and explicit origin/<branch> values are honoured as supplied.

func ResolveBranchCommitContext added in v0.70.5

func ResolveBranchCommitContext(ctx context.Context, repoPath, branch string) (string, error)

func Run

func Run(dir string, args ...string) (string, string, error)

func RunCheck

func RunCheck(dir string, args ...string) bool

func RunCheckContext added in v0.70.5

func RunCheckContext(ctx context.Context, dir string, args ...string) bool

func RunContext added in v0.30.0

func RunContext(ctx context.Context, dir string, args ...string) (string, string, error)

func RunContextEnv added in v0.42.0

func RunContextEnv(ctx context.Context, dir string, env []string, args ...string) (string, string, error)

func RunOutput

func RunOutput(dir string, args ...string) (string, error)

func RunOutputContext added in v0.30.0

func RunOutputContext(ctx context.Context, dir string, args ...string) (string, error)

func SetupReadOnlySession added in v0.70.5

func SetupReadOnlySession(ctx context.Context, repoPath, worktreePath, branch string, fetch bool) (string, error)

func SetupSession

func SetupSession(ctx context.Context, repoPath, worktreePath, branchName, baseBranch string, fetch bool) error

func TeardownSession

func TeardownSession(repoPath, worktreePath, branchName string) error

TeardownSession removes a session's worktree and branch. It is idempotent: a missing or broken worktree is treated as already-removed and never blocks dropping the session. `git worktree remove --force` fails with exit 128 when the directory is gone or its .git link is broken; when git still lists the path as a registered worktree of this repo (as it does for a broken link) we remove the directory directly and prune the stale registration so a broken worktree can't wedge delete forever (#741). A failure where the path is not a registered worktree — an unreachable/invalid source repo, or a stale path pointing somewhere graith doesn't own — is surfaced so the session is kept for retry rather than dropped (and nothing unowned is deleted).

func UnpushedCommitCount

func UnpushedCommitCount(worktreePath, baseBranch string) (int, error)

UnpushedCommitCount returns the number of commits on HEAD that have not been pushed to the remote.

It compares against the current branch's remote tracking ref (origin/<branch>) when that ref exists. This answers "have I pushed my commits?" and reflects real push state without any network I/O: `git push` updates the local tracking ref, and after a branch's PR is merged the tracking ref still points at the pushed tip, so the count correctly reads 0 (no false "N ahead of main"). See issue #197.

When the branch has never been pushed (no tracking ref) it falls back to counting commits ahead of the base branch — everything that would be pushed. The base ref itself may be stale without a fetch; a periodic fetch in the daemon keeps it reasonably fresh.

func UnpushedCommitSummaries added in v0.3.0

func UnpushedCommitSummaries(worktreePath, baseBranch string) ([]string, error)

func WorktreeGitDirs added in v0.19.0

func WorktreeGitDirs(worktreePath string) (gitDir, commonDir string, err error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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