git

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package git wraps all git CLI interactions. No other package shells out to git.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BranchExists

func BranchExists(ctx context.Context, dir, branch string) bool

BranchExists checks if a branch exists locally.

func CheckoutBranch

func CheckoutBranch(ctx context.Context, dir, branch string) error

CheckoutBranch checks out an existing branch.

func Clone

func Clone(ctx context.Context, url, dir string) error

Clone clones a repository to the given directory.

func Commit

func Commit(ctx context.Context, dir, message string) error

Commit stages all changes and creates a commit.

func ConfigGet

func ConfigGet(ctx context.Context, dir, key string) (string, error)

ConfigGet returns a git config value.

func CreateBranch

func CreateBranch(ctx context.Context, dir, branch string) error

CreateBranch creates and checks out a new branch.

func CurrentBranch

func CurrentBranch(ctx context.Context, dir string) (string, error)

CurrentBranch returns the current branch name.

func DetectSpecFromBranch

func DetectSpecFromBranch(ctx context.Context, dir string) string

DetectSpecFromBranch attempts to detect the spec ID from the current branch.

func Diff

func Diff(ctx context.Context, dir, baseRef string) (string, error)

Diff returns the diff for the current branch compared to a base ref.

func DiffStaged

func DiffStaged(ctx context.Context, dir string) (string, error)

DiffStaged returns the diff of staged changes.

func EnsureSpecsRepo

func EnsureSpecsRepo(ctx context.Context, cfg *config.SpecsRepoConfig) (string, error)

EnsureSpecsRepo clones the specs repo if not present, otherwise fetches latest.

func Fetch

func Fetch(ctx context.Context, dir string) error

Fetch fetches from origin in the given repo directory.

func HasChanges

func HasChanges(ctx context.Context, dir string) (bool, error)

HasChanges returns true if there are uncommitted changes.

func IsGitRepo

func IsGitRepo(dir string) bool

IsGitRepo checks if the directory is inside a git repository.

func ListArchiveFiles

func ListArchiveFiles(cfg *config.SpecsRepoConfig, archiveDir string) ([]string, error)

ListArchiveFiles returns all archived spec files.

func ListSpecFiles

func ListSpecFiles(cfg *config.SpecsRepoConfig) ([]string, error)

ListSpecFiles returns all spec files in the specs repo root.

func ListTriageFiles

func ListTriageFiles(cfg *config.SpecsRepoConfig) ([]string, error)

ListTriageFiles returns all triage files in the triage/ directory.

func Log

func Log(ctx context.Context, dir string, n int, format string) (string, error)

Log returns recent commit messages.

func Push

func Push(ctx context.Context, dir, branch string) error

Push pushes to origin for the given branch.

func PushLocalEdits

func PushLocalEdits(ctx context.Context, cfg *config.SpecsRepoConfig, commitMsg string) (bool, error)

PushLocalEdits commits any uncommitted changes in the specs repo and pushes them. Unlike WithSpecsRepo, which resets to remote state before applying a mutation, PushLocalEdits preserves existing local edits — it is the backing implementation for `spec push`. Returns true if changes were found and pushed. On a push conflict it fetches and rebases rather than hard-resetting, preserving the committed local work.

func ReadSpecFile

func ReadSpecFile(cfg *config.SpecsRepoConfig, filename string) ([]byte, error)

ReadSpecFile reads a spec file from the specs repo.

func Rebase

func Rebase(ctx context.Context, dir, ref string) error

Rebase rebases the current branch onto the given ref.

func ResetHard

func ResetHard(ctx context.Context, dir, ref string) error

ResetHard resets the working tree to a specific ref.

func Run

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

Run executes a git command in the given directory with a timeout.

func SpecBranchName

func SpecBranchName(specID string, stepNumber int, slug string) string

SpecBranchName generates a branch name for a build step.

func SpecFilePath

func SpecFilePath(cfg *config.SpecsRepoConfig, filename string) string

SpecFilePath returns the absolute path to a spec file in the specs repo.

func SpecsRepoDir

func SpecsRepoDir(cfg *config.SpecsRepoConfig) string

SpecsRepoDir returns the local path for the specs repo clone.

func SpecsRepoURL

func SpecsRepoURL(cfg *config.SpecsRepoConfig) string

SpecsRepoURL returns the clone URL for the specs repo. If a token is configured, it is embedded in the URL for passwordless auth.

func Status

func Status(ctx context.Context, dir string) (string, error)

Status returns the short status output.

func TriageFilePath

func TriageFilePath(cfg *config.SpecsRepoConfig, filename string) string

TriageFilePath returns the absolute path to a triage file.

func UserEmail

func UserEmail(ctx context.Context) string

UserEmail returns the configured git user.email.

func UserName

func UserName(ctx context.Context) string

UserName returns the configured git user.name.

func WithSpecsRepo

func WithSpecsRepo(ctx context.Context, cfg *config.SpecsRepoConfig, mutate func(repoPath string) (commitMsg string, err error)) error

WithSpecsRepo fetches the latest, calls the mutator function, then commits and pushes. If the push fails due to a conflict, it retries up to maxPushRetries times.

Types

type BranchInfo

type BranchInfo struct {
	SpecNumber string // e.g., "042"
	StepNumber string // e.g., "1"
	Slug       string // e.g., "token-bucket"
}

BranchInfo represents parsed branch name information.

func ParseSpecBranch

func ParseSpecBranch(branch string) *BranchInfo

ParseSpecBranch extracts spec and step info from a branch name. Returns nil if the branch doesn't match the spec branch pattern.

Jump to

Keyboard shortcuts

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