gitutil

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package gitutil provides shared git helper functions used by baseline and history packages.

Index

Constants

View Source
const CommandTimeout = 30 * time.Second

CommandTimeout is the timeout for git commands.

View Source
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

View Source
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

func ReadRef(ref string) (string, bool)

ReadRef resolves a git ref to its current SHA. Returns ("", false) if the ref does not exist.

func ReadRefContent added in v1.1.3

func ReadRefContent(ref string) ([]byte, error)

ReadRefContent reads the blob content stored at a git ref. Returns (nil, nil) if the ref does not exist.

func RefExists

func RefExists(ref string) bool

RefExists checks if a git ref exists.

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

func WriteRef(ref string, content []byte, oldSHA string) error

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.

Jump to

Keyboard shortcuts

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