Documentation
¶
Overview ¶
Package gitutil manages git worktree lifecycle and credential injection for git operations.
It provides DumpWorkerState (captures recent commits and status to a debug file), IsWorktreeClean (detects uncommitted changes), RemoveWorktree (deletes a worktree directory, prunes metadata, and removes the worker branch), and GitCredEnv (credential environment injection for git network operations). Used by the worker close, spawn, daemon, and ask paths.
Plane: shared
Index ¶
- func AnonymousGitEnv(baseEnv []string) []string
- func BranchName(dir string) string
- func DumpWorkerState(sessionName, workDir, workerName string) (string, error)
- func ForgeToken() string
- func ForgeTokenEnv() string
- func ForgejoGitEnv(baseEnv []string, token string) []string
- func GitCredEnvWithToken(token string) []string
- func GitHubAppGitEnv(baseEnv []string, remoteURL, owner, repo, token string) []string
- func IsWorktreeClean(workDir string) (bool, error)
- func LinkedWorktreeCommonDir(dir string) string
- func RemoteURL(dir string) (string, error)
- func RemoveWorktree(projectDir, workDir, branch string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnonymousGitEnv ¶
AnonymousGitEnv returns a complete child environment with credential sources disabled.
func BranchName ¶
BranchName returns the current git branch for dir. Returns "" if in detached HEAD state or on any error.
func DumpWorkerState ¶
DumpWorkerState captures git state for debugging. Returns the path to the dump file.
func ForgeToken ¶
func ForgeToken() string
ForgeToken returns the configured token for Forgejo/Gitea-compatible remotes.
func ForgeTokenEnv ¶
func ForgeTokenEnv() string
ForgeTokenEnv returns the first configured token environment variable for Forgejo/Gitea-compatible remotes.
func ForgejoGitEnv ¶
ForgejoGitEnv returns a complete child environment using only the resolved token.
func GitCredEnvWithToken ¶
GitCredEnvWithToken returns environment variables for git network operations using an already-resolved token. Use this when a caller has a single credential source of truth and must not re-resolve from ambient env vars.
func GitHubAppGitEnv ¶
GitHubAppGitEnv returns a complete child-process environment that routes a GitHub origin through canonical HTTPS and uses only the supplied App token.
func IsWorktreeClean ¶
IsWorktreeClean checks whether the worktree has uncommitted changes. Returns (true, nil) if clean, (false, nil) if dirty, or (false, err) if the git command itself failed (e.g. missing directory, timeout).
func LinkedWorktreeCommonDir ¶
LinkedWorktreeCommonDir returns the shared .git directory if dir is a linked git worktree. Returns "" if dir is the main repo or on any error. Uses a single `git rev-parse --git-dir --git-common-dir` call to avoid redundant subprocesses.
func RemoveWorktree ¶
RemoveWorktree removes a git worktree and its branch. Uses os.RemoveAll + git worktree prune instead of git worktree remove for faster cleanup without subprocess timeout risks.
Types ¶
This section is empty.