commit

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: MIT Imports: 14 Imported by: 0

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

View Source
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
	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

type CommitError struct {
	Code    int
	Message string
}

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
	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.

type RewordRequest

type RewordRequest struct {
	Message string // required
	Branch  string // target branch ref; empty = HEAD
	DryRun  bool
}

RewordRequest holds inputs for a reword operation.

type RewordResult

type RewordResult struct {
	SHA    string `json:"sha"`
	Ref    string `json:"ref"`
	Parent string `json:"parent"`
	Tree   string `json:"tree"`
	OldSHA string `json:"oldSha"`
}

RewordResult is the JSON-serializable output of a successful reword.

Jump to

Keyboard shortcuts

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