Documentation
¶
Overview ¶
Package gitutil provides shared git helper functions used by baseline and history packages.
Index ¶
- Constants
- Variables
- func GetCurrentBranch() string
- func GetCurrentCommit() string
- func IsGitRepo() bool
- func ReadRef(ref string) (string, bool)
- func ReadRefContent(ref string) ([]byte, error)
- func RefExists(ref string) bool
- func ResolveGitPath() string
- func WriteRef(ref string, content []byte, oldSHA string) error
Constants ¶
const CommandTimeout = 30 * time.Second
CommandTimeout is the timeout for git commands.
const ZeroSHA = "0000000000000000000000000000000000000000"
ZeroSHA is the 40-character zero SHA used to indicate "ref does not exist" in git update-ref's compare-and-swap mode.
Variables ¶
var ErrRefConflict = errors.New("git ref conflict: current value differs from expected")
ErrRefConflict is returned when a compare-and-swap write fails because the ref's current value doesn't match the expected old SHA.
Functions ¶
func GetCurrentBranch ¶ added in v1.1.3
func GetCurrentBranch() string
GetCurrentBranch returns the current git branch name, or empty string if not on a branch.
func GetCurrentCommit ¶ added in v1.1.3
func GetCurrentCommit() string
GetCurrentCommit returns the current git commit hash, or empty string if not in a repo.
func IsGitRepo ¶
func IsGitRepo() bool
IsGitRepo checks if the current directory is inside a git repository.
func ReadRef ¶ added in v1.1.3
ReadRef resolves a git ref to its current SHA. Returns ("", false) if the ref does not exist.
func ReadRefContent ¶ added in v1.1.3
ReadRefContent reads the blob content stored at a git ref. Returns (nil, nil) if the ref does not exist.
func ResolveGitPath ¶
func ResolveGitPath() string
ResolveGitPath finds the git executable path once and caches it. This satisfies security scanners that warn about PATH-based command execution.
func WriteRef ¶ added in v1.1.3
WriteRef writes content as a blob and updates a git ref to point to it.
The oldSHA parameter controls compare-and-swap behavior:
- "" (empty): unconditional write (no CAS)
- ZeroSHA: create-only (fails if ref already exists)
- any other SHA: CAS (fails if ref's current value != oldSHA)
Returns ErrRefConflict if the CAS check fails.
Types ¶
This section is empty.