Documentation
¶
Overview ¶
Amend and Reword implement tip-commit rewriting with CAS safety.
Package commit implements the two-phase commit pipeline. Phase A (parallel-safe): tmp index, validate, stage, write-tree, commit-tree. Phase B (serialized): ref lock, CAS check with retry, update-ref, oplog.
Index ¶
Constants ¶
const ( ExitCASExhausted = 7 ExitWriteTree = 9 ExitCommitTree = 10 )
Exit codes for commit-specific errors.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AmendRequest ¶
type AmendRequest struct {
Message string // empty = keep existing message
FileSpecs []FileSpec // files to stage into the amended commit
Branch string // target branch ref; empty = HEAD
Trailers []string // user-provided trailers ("Key: Value" format)
Force bool // skip gitignore check
DryRun bool
}
AmendRequest holds inputs for an amend operation.
type AmendResult ¶
type AmendResult struct {
SHA string `json:"sha"`
Ref string `json:"ref"`
Parent string `json:"parent"`
Tree string `json:"tree"`
OldSHA string `json:"oldSha"`
Attempts int `json:"attempts"`
}
AmendResult is the JSON-serializable output of a successful amend.
type CommitError ¶
CommitError carries a structured exit code alongside the error message.
func (*CommitError) Error ¶
func (e *CommitError) Error() string
type CommitRequest ¶
type CommitRequest struct {
Message string
Files []string // plain file paths (whole-file staging)
FileSpecs []FileSpec // files with optional hunk selection (takes priority over Files)
Branch string // empty = current branch
Trailers []string // user-provided trailers ("Key: Value" format)
AllowEmpty bool
Force bool // skip gitignore check
DryRun bool
}
CommitRequest holds all inputs for a single commit operation.
type CommitResult ¶
type CommitResult struct {
SHA string `json:"sha"`
Ref string `json:"ref"`
Parent string `json:"parent"`
Tree string `json:"tree"`
Attempts int `json:"attempts"`
}
CommitResult is the JSON-serializable output of a successful commit.
type FileSpec ¶
type FileSpec struct {
Path string
Hunks []int // nil = whole file, non-nil = selected hunk indices (1-based)
}
FileSpec describes a file with optional hunk selection for staging.
type Pipeline ¶
type Pipeline struct {
SafegitDir string
Config repo.Config
// PhaseADone is called (if non-nil) after Phase A completes but before
// the ref lock is acquired. Used by tests to inject concurrent commits.
PhaseADone func()
}
Pipeline orchestrates the full commit flow.
func (*Pipeline) Amend ¶
func (p *Pipeline) Amend(ctx context.Context, req AmendRequest) (*AmendResult, error)
Amend rewrites the tip of the current branch with new files staged. Uses tmp index seeded from HEAD, stages files, builds a new commit with parent = HEAD^ and lock-and-CAS updates the ref.
func (*Pipeline) Execute ¶
func (p *Pipeline) Execute(ctx context.Context, req CommitRequest) (*CommitResult, error)
Execute runs the full two-phase commit pipeline. On CAS miss it retries from Phase A up to Config.Commit.CASMaxAttempts times.
func (*Pipeline) Reword ¶
func (p *Pipeline) Reword(ctx context.Context, req RewordRequest) (*RewordResult, error)
Reword rewrites only the commit message of the tip of the current branch. Tree and parent remain unchanged. Retries on CAS miss.