gitutil

package
v0.0.0-...-03ca8a1 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileAddedAt

func FileAddedAt(repoRoot, path string) (time.Time, bool)

FileAddedAt returns the author date of the commit that first introduced the file at path in the repository at repoRoot. The path may be absolute; it is made relative to repoRoot before being passed to git so that --follow works correctly. The second return value is false when the file has no recorded git history (untracked, or git unavailable).

func FileAddedMeta

func FileAddedMeta(repoRoot, path string) (time.Time, string, string, bool)

FileAddedMeta returns metadata for the commit that first introduced path, following renames to preserve original attribution.

func FileAddedMetaMany

func FileAddedMetaMany(repoRoot string, paths []string) map[string]FileMetaResult

FileAddedMetaMany returns add metadata for multiple files using a single git log call. This avoids the O(N) subprocess overhead of calling FileAddedMeta per file. Paths may be absolute; the returned map key is the original path. Files missing from the result (e.g. untracked or renamed) should fall back to per-file FileAddedMeta for --follow semantics.

func FindAllChangesDirs

func FindAllChangesDirs(root string) ([]string, error)

FindAllChangesDirs recursively finds all ".changes" directories under root. It does not recurse into ".git" directories or into ".changes" directories themselves (nested ".changes" hierarchies are not supported). All returned paths are guaranteed to be within root.

func FindGitRoot

func FindGitRoot(startPath string) (string, bool, error)

FindGitRoot walks up from startPath until it finds a directory that contains a ".git" entry. It returns the root path and true when found. If the filesystem root is reached without finding ".git", it returns startPath and false.

func HasAbbreviatedVersionTags

func HasAbbreviatedVersionTags(repoRoot, tagPrefix string) (bool, error)

HasAbbreviatedVersionTags reports whether the repository at repoRoot contains any abbreviated major (e.g. v1) or major.minor (e.g. v1.2) tags with the given prefix. Used to auto-detect the alias-tags release policy.

func IsWithinDir

func IsWithinDir(parent, target string) bool

IsWithinDir reports whether target is inside (or equal to) parent. Both paths must be absolute and are cleaned before comparison.

func ListSemVerTags

func ListSemVerTags(repoRoot string, tagPrefix string) ([]semver.Tag, error)

ListSemVerTags returns every SemVer tag in the repository at repoRoot, optionally scoped by tagPrefix, ordered from oldest to newest by SemVer. When git is unavailable or the repository has no matching tags, an empty slice and no error are returned.

Tag name and date are fetched in a single git call using --format so the number of subprocess invocations is O(1) instead of O(n tags). %(creatordate) gives the commit author date for lightweight tags and the tagger date for annotated tags; both are accurate enough for version attribution ordering.

func RunGit

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

RunGit runs a git command in dir with a default timeout and returns stdout.

func RunGitWithContext

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

RunGitWithContext runs a git command in dir using the provided context for cancellation and deadline control.

func SplitLines

func SplitLines(s string) []string

SplitLines splits s into lines, returning nil when s is blank.

Types

type FileMetaResult

type FileMetaResult struct {
	AddedAt          time.Time
	AddedCommitHash  string
	OriginalFilename string
}

FileAddedMeta holds the metadata returned by FileAddedMetaMany for a single file.

Jump to

Keyboard shortcuts

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