gitutil

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 8 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnonymousGitEnv

func AnonymousGitEnv(baseEnv []string) []string

AnonymousGitEnv returns a complete child environment with credential sources disabled.

func BranchName

func BranchName(dir string) string

BranchName returns the current git branch for dir. Returns "" if in detached HEAD state or on any error.

func DumpWorkerState

func DumpWorkerState(sessionName, workDir, workerName string) (string, error)

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

func ForgejoGitEnv(baseEnv []string, token string) []string

ForgejoGitEnv returns a complete child environment using only the resolved token.

func GitCredEnvWithToken

func GitCredEnvWithToken(token string) []string

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

func GitHubAppGitEnv(baseEnv []string, remoteURL, owner, repo, token string) []string

GitHubAppGitEnv returns a complete child-process environment that routes a GitHub origin through canonical HTTPS and uses only the supplied App token.

func IsWorktreeClean

func IsWorktreeClean(workDir string) (bool, error)

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

func LinkedWorktreeCommonDir(dir string) string

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 RemoteURL

func RemoteURL(dir string) (string, error)

RemoteURL returns the origin remote URL for the given directory.

func RemoveWorktree

func RemoveWorktree(projectDir, workDir, branch string) error

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.

Jump to

Keyboard shortcuts

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