git

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 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

View Source
const (

	// SpecsSubDir is the sub-directory within the specs repo where spec
	// files are stored. All spec, triage, and archive content lives under
	// this path.
	SpecsSubDir = "specs"
)

Variables

This section is empty.

Functions

func ArchiveSpec added in v0.8.0

func ArchiveSpec(ctx context.Context, cfg *config.SpecsRepoConfig, specID, archiveDir string) error

ArchiveSpec moves a spec from specs/ to archive/ and commits the change.

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 CommittedFiles added in v0.7.0

func CommittedFiles(ctx context.Context, dir, ref string) ([]string, error)

CommittedFiles returns the list of files changed in the given 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 DiffNameOnly added in v0.7.0

func DiffNameOnly(ctx context.Context, dir, refA, refB string) ([]string, error)

DiffNameOnly returns file paths changed between two refs.

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 HasUnpushedCommits added in v0.7.0

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

HasUnpushedCommits returns true if there are local commits not on the remote branch.

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/ directory of the specs repo.

func ListTriageFiles

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

ListTriageFiles returns all triage files in the specs/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 RebaseAbort added in v0.7.0

func RebaseAbort(ctx context.Context, dir string)

RebaseAbort cancels an in-progress rebase, restoring the repo to its pre-rebase state. Safe to call even if no rebase is in progress.

func ResetHard

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

ResetHard resets the working tree to a specific ref.

func RestoreSpec added in v0.8.0

func RestoreSpec(ctx context.Context, cfg *config.SpecsRepoConfig, specID, archiveDir string) error

RestoreSpec moves a spec from archive/ back to specs/ and commits the change.

func RevParse added in v0.7.0

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

RevParse returns the SHA for a 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. If ctx has no deadline, the defaultTimeout is applied automatically.

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 exactly once, then commits and pushes. If the push fails due to a concurrent update, it rebases (rather than re-running the mutation) and retries the push.

After a successful rebase, it verifies that no files touched by the local commit were also changed upstream. This catches the case where two users concurrently mutate the same spec — the rebase may auto-merge different hunks, but the result would be semantically wrong (e.g. double-advance).

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