git

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package git will adapt git operations for the Go port.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetachedPRWorktreePath added in v0.11.1

func DetachedPRWorktreePath(worktreeRoot, projectID string, prNumber int64) string

DetachedPRWorktreePath returns the managed shared detached worktree path that CreateWorktree claims for a PR (looper-fix-<project>-pr-<N>-detached). Callers that must read ownership markers before CreateWorktree revokes them should probe this candidate path even when no checkpoint worktree exists.

func IsReservedReviewerScratchBaseName added in v0.11.3

func IsReservedReviewerScratchBaseName(name string) bool

IsReservedReviewerScratchBaseName reports whether name matches the disposable reviewer scratch grammar (exported for focused tests).

func ScrubReservedReviewerScratch added in v0.11.3

func ScrubReservedReviewerScratch(ctx context.Context, gitPath, worktreePath string) error

ScrubReservedReviewerScratch removes disposable reviewer submit scratch from a managed worktree root immediately before ordinary PrepareWorktree cleanliness.

It enumerates the worktree root directly (not via git status). Only regular files matching reservedReviewerScratchBaseName that are absent from both the Git index and HEAD tree are deleted. Symlinks and directories are left alone. Files tracked by HEAD but staged for index removal (e.g. after `git rm --cached`) remain ordinary dirt and are preserved. Delete failures fail closed.

gitPath must be the configured Git executable (tools.gitPath); callers must not hard-code "git" when a non-PATH binary is configured.

Types

type CheckoutMode

type CheckoutMode string
const (
	CheckoutModeBranch   CheckoutMode = "branch"
	CheckoutModeDetached CheckoutMode = "detached"
)

type CleanupWorktreeInput

type CleanupWorktreeInput struct {
	ProjectID         string
	RepoPath          string
	WorktreeRoot      string
	WorktreePath      string
	Branch            string
	ProtectedBranches []string
	// AdmitStart, when set, wraps the destructive `git worktree remove`
	// process Start so callers can hold admission across Start only (not
	// Wait). Runtime cleanup uses this for R7 atomicity with MarkDegraded:
	// point-in-time AllowClaim leaves a window before cmd.Start.
	AdmitStart func(start func() error) error
}

type CommitInput

type CommitInput struct {
	RepoPath     string
	WorktreeRoot string
	WorktreePath string
	Message      string
}

type CommitResult

type CommitResult struct {
	CommitSHA string
}

type CreateWorktreeInput

type CreateWorktreeInput struct {
	ProjectID         string
	RepoPath          string
	WorktreeRoot      string
	Branch            string
	BaseBranch        string
	PRNumber          int64
	ProtectedBranches []string
	CheckoutMode      CheckoutMode
}

type DiscardWorktreeChangesInput added in v0.11.0

type DiscardWorktreeChangesInput struct {
	RepoPath     string
	WorktreeRoot string
	WorktreePath string
}

DiscardWorktreeChangesInput discards tracked and untracked local changes in a managed worktree, leaving HEAD and the worktree directory itself intact.

type DiscardWorktreeChangesResult added in v0.11.0

type DiscardWorktreeChangesResult struct {
	WorktreePath string
	WasDirty     bool
	NoOp         bool
}

DiscardWorktreeChangesResult reports whether discard mutated the worktree.

type Gateway

type Gateway struct {
	// contains filtered or unexported fields
}

func New

func New(options Options) *Gateway

func (*Gateway) AssertWritableBranch

func (g *Gateway) AssertWritableBranch(branch string, protectedBranches []string) error

func (*Gateway) CleanupWorktree

func (g *Gateway) CleanupWorktree(ctx context.Context, input CleanupWorktreeInput) error

func (*Gateway) Commit

func (g *Gateway) Commit(ctx context.Context, input CommitInput) (CommitResult, error)

func (*Gateway) CreateBranch

func (g *Gateway) CreateBranch(ctx context.Context, repoPath, branch, startPoint string, protectedBranches []string) error

func (*Gateway) CreateWorktree

func (g *Gateway) CreateWorktree(ctx context.Context, input CreateWorktreeInput) (storage.WorktreeRecord, error)

func (*Gateway) DetectGitHubRepo

func (g *Gateway) DetectGitHubRepo(ctx context.Context, repoPath string) (string, error)

func (*Gateway) DetectOriginRemote added in v0.10.4

func (g *Gateway) DetectOriginRemote(ctx context.Context, repoPath string) (OriginRemote, error)

DetectOriginRemote reads remote.origin.url and extracts host + owner/name when possible.

func (*Gateway) DiscardWorktreeChanges added in v0.11.0

func (g *Gateway) DiscardWorktreeChanges(ctx context.Context, input DiscardWorktreeChangesInput) (DiscardWorktreeChangesResult, error)

DiscardWorktreeChanges hard-resets tracked files and removes untracked files in a managed worktree. It never deletes the worktree directory, remote branches, or force-pushes.

func (*Gateway) FetchBranch added in v0.7.4

func (g *Gateway) FetchBranch(ctx context.Context, repoPath, remote, branch string) error

func (*Gateway) InspectHead

func (g *Gateway) InspectHead(ctx context.Context, input InspectHeadInput) (InspectHeadResult, error)

func (*Gateway) IsAncestor added in v0.7.4

func (g *Gateway) IsAncestor(ctx context.Context, repoPath, ancestor, descendant string) (bool, error)

func (*Gateway) IsWorktreeClean added in v0.9.0

func (g *Gateway) IsWorktreeClean(ctx context.Context, worktreePath string) (bool, error)

func (*Gateway) ListWorktrees

func (g *Gateway) ListWorktrees(ctx context.Context, repoPath string) ([]WorktreeListEntry, error)

func (*Gateway) MergeBaseIntoWorktree added in v0.10.0

func (g *Gateway) MergeBaseIntoWorktree(ctx context.Context, input MergeBaseInput) (MergeBaseResult, error)

MergeBaseIntoWorktree fetches the base branch and merges it into the worktree. On a clean merge it returns AlreadyUpToDate as appropriate; on conflicts it leaves the conflict markers in place and returns Conflicted=true so the caller can hand the worktree to an agent; on any other merge failure it aborts to keep the worktree clean and returns the error.

func (*Gateway) PrepareWorktree

func (g *Gateway) PrepareWorktree(ctx context.Context, input PrepareWorktreeInput) (PrepareWorktreeResult, error)

func (*Gateway) Push

func (g *Gateway) Push(ctx context.Context, input PushInput) error

func (*Gateway) RestoreWorktree

func (g *Gateway) RestoreWorktree(ctx context.Context, input RestoreWorktreeInput) (*storage.WorktreeRecord, error)

func (*Gateway) ScrubReservedReviewerScratch added in v0.11.3

func (g *Gateway) ScrubReservedReviewerScratch(ctx context.Context, worktreePath string) error

ScrubReservedReviewerScratch removes disposable reviewer submit scratch using this gateway's configured Git executable.

func (*Gateway) WorktreeClean added in v0.9.0

func (g *Gateway) WorktreeClean(ctx context.Context, worktreePath string) (bool, error)

type InspectHeadInput

type InspectHeadInput struct {
	RepoPath     string
	WorktreeRoot string
	WorktreePath string
	BaseRef      string
}

type InspectHeadResult

type InspectHeadResult struct {
	HeadSHA               string
	NewCommitSHAs         []string
	HasUncommittedChanges bool
	ChangedFiles          []string
}

type MergeBaseInput added in v0.10.0

type MergeBaseInput struct {
	WorktreePath string
	Remote       string
	BaseBranch   string
}

MergeBaseInput asks to merge a remote base branch into a worktree.

type MergeBaseResult added in v0.10.0

type MergeBaseResult struct {
	AlreadyUpToDate bool
	// Conflicted is true when the merge left conflict markers in the worktree for
	// an agent to resolve (the merge is intentionally NOT aborted in that case).
	Conflicted bool
}

MergeBaseResult reports the outcome of a base merge.

type Options

type Options struct {
	GitPath string
	Repos   *storage.Repositories
	Now     func() time.Time
}

type OriginRemote added in v0.10.4

type OriginRemote struct {
	URL  string
	Host string
	Repo string // owner/name
}

OriginRemote is the parsed remote.origin URL for a local checkout.

type PrepareWorktreeInput

type PrepareWorktreeInput struct {
	RepoPath        string
	WorktreeRoot    string
	WorktreePath    string
	Branch          string
	Ref             string
	ExpectedHeadSHA string
	Remote          string
}

type PrepareWorktreeResult

type PrepareWorktreeResult struct {
	HeadSHA string
	Clean   bool
}

type ProtectedBranchError

type ProtectedBranchError struct {
	Branch string
}

func (*ProtectedBranchError) Error

func (e *ProtectedBranchError) Error() string

type PushInput

type PushInput struct {
	RepoPath              string
	WorktreeRoot          string
	WorktreePath          string
	Branch                string
	Remote                string
	ExpectedRemoteHeadSHA string
	ProtectedBranches     []string
}

type RemoteHeadChangedError

type RemoteHeadChangedError struct {
	Branch          string
	ExpectedHeadSHA string
	ActualHeadSHA   string
}

func (*RemoteHeadChangedError) Error

func (e *RemoteHeadChangedError) Error() string

type RestoreWorktreeInput

type RestoreWorktreeInput struct {
	ProjectID            string
	RepoPath             string
	Branch               string
	WorktreeRoot         string
	CheckoutMode         CheckoutMode
	ExpectedWorktreePath string
}

type WorktreeListEntry

type WorktreeListEntry struct {
	Path    string
	Branch  string
	HeadSHA string
	Bare    bool
}

Jump to

Keyboard shortcuts

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