Documentation
¶
Overview ¶
Package git provides domain-grouped interfaces and backend orchestration for Git repository operations.
The root package exposes capability-oriented interfaces and shared types, while concrete implementations live in backend sub-packages such as embedded and cli.
Index ¶
- Constants
- Variables
- func ErrAlreadyExists(kind, name string) *errors.AppError
- func ErrAmbiguousRef(refname string) *errors.AppError
- func ErrCheckedOutBranch(name string) *errors.AppError
- func ErrConfigNotFound(key string) *errors.AppError
- func ErrConflict(path string) *errors.AppError
- func ErrDetachedHead() *errors.AppError
- func ErrEmbeddedUnsupported(operation string) *errors.AppError
- func ErrFileTooLarge(path, revision string, size, limit int64) *errors.AppError
- func ErrIdentityMissing(key string) *errors.AppError
- func ErrInternal(cause error) *errors.AppError
- func ErrInvalidConfigKey(key string) *errors.AppError
- func ErrInvalidLineRange(start, end int) *errors.AppError
- func ErrInvalidPath(path string) *errors.AppError
- func ErrInvalidTransport(kind string) *errors.AppError
- func ErrNetwork(cause error) *errors.AppError
- func ErrPushRejected(refname, reason string) *errors.AppError
- func ErrRefNotFound(refname string) *errors.AppError
- func ErrRemoteAuth(message string) *errors.AppError
- func ErrRemoteNotFound(name string) *errors.AppError
- func ErrRepoNotFound(path string) *errors.AppError
- func ErrSigningKeyMissing(key string) *errors.AppError
- func ErrSigningNotSupported() *errors.AppError
- type BlameLine
- type BlameOption
- type BlameOptions
- type Blamer
- type Branch
- type BranchFilter
- type Checker
- type CheckoutOption
- type CheckoutOptions
- type CherryPickOption
- type CherryPickOptions
- type CherryPicker
- type CleanOption
- type CleanOptions
- type Commit
- type CommitOption
- type CommitOptions
- type Committer
- type ConfigReader
- type DescribeOption
- type DescribeOptions
- type DiffEntry
- type DiffOption
- type DiffOptions
- type DiffStats
- type Differ
- type EntryKind
- type EntryState
- type Executor
- type FetchOption
- type FetchOptions
- type FileStatus
- type GrepMatch
- type GrepOption
- type GrepOptions
- type IndexManager
- type Inspector
- type LogOptions
- type LogReader
- type Maintainer
- type MergeOption
- type MergeOptions
- type MergeResult
- type Merger
- type Oid
- type OpenOptions
- type Option
- type PushOption
- type PushOptions
- type RebaseOption
- type RebaseOptions
- type RebaseResult
- type Rebaser
- type RefManager
- type Reference
- type Remote
- type RemoteManager
- type Repo
- func Clone(ctx context.Context, url, path string, opts ...Option) (*Repo, error)
- func Discover(path string, opts ...Option) (*Repo, error)
- func DiscoverWithAuth(path string, transport auth.Transport, opts ...Option) (*Repo, error)
- func Init(path string, opts ...Option) (*Repo, error)
- func InitBare(path string, opts ...Option) (*Repo, error)
- func Open(path string, opts ...Option) (*Repo, error)
- func OpenWithAuth(path string, transport auth.Transport, opts ...Option) (*Repo, error)
- func (r *Repo) Blame(revision, path string, opts ...BlameOption) ([]BlameLine, error)
- func (r *Repo) Checkout(target string, paths ...string) error
- func (r *Repo) CherryPick(revision string) error
- func (r *Repo) CherryPickAbort() error
- func (r *Repo) CherryPickContinue() error
- func (r *Repo) Clean(opts ...CleanOption) ([]string, error)
- func (r *Repo) Commit(message string, opts ...CommitOption) (Oid, error)
- func (r *Repo) ConfigGet(key string) (string, error)
- func (r *Repo) ConfigGetAll(key string) ([]string, error)
- func (r *Repo) ConfigSet(key, value string) error
- func (r *Repo) CreateBranch(name, target string) error
- func (r *Repo) CreateSignedTag(name, target, message string, opts SignOptions) error
- func (r *Repo) CreateTag(name, target, message string) error
- func (r *Repo) DeleteBranch(name string) error
- func (r *Repo) DeleteTag(name string) error
- func (r *Repo) Describe(revision string) (string, error)
- func (r *Repo) Diff(from, to string) ([]DiffEntry, error)
- func (r *Repo) DiffStats(from, to string) (DiffStats, error)
- func (r *Repo) Exec(args ...string) ([]byte, error)
- func (r *Repo) Fetch(ctx context.Context, remote string, opts ...FetchOption) error
- func (r *Repo) FileAt(revision, path string) ([]byte, error)
- func (r *Repo) FileAtBounded(revision, path string, maxBytes int64) ([]byte, error)
- func (r *Repo) Fsck() error
- func (r *Repo) GC() error
- func (r *Repo) Grep(pattern string, paths ...string) ([]GrepMatch, error)
- func (r *Repo) Head() (Reference, error)
- func (r *Repo) IsAncestor(a, b string) (bool, error)
- func (r *Repo) IsDirty() (bool, error)
- func (r *Repo) ListBranches(filter BranchFilter) ([]Branch, error)
- func (r *Repo) ListEntries(revision, path string) ([]TreeEntry, error)
- func (r *Repo) ListRemotes() ([]Remote, error)
- func (r *Repo) ListTags() ([]Tag, error)
- func (r *Repo) Log(opts LogOptions) ([]Commit, error)
- func (r *Repo) Merge(revision string) error
- func (r *Repo) MergeAbort() error
- func (r *Repo) MergeBase(a, b string) (Oid, error)
- func (r *Repo) Prune() error
- func (r *Repo) Push(ctx context.Context, remote string, opts ...PushOption) error
- func (r *Repo) Rebase(onto string) error
- func (r *Repo) RebaseAbort() error
- func (r *Repo) RebaseContinue() error
- func (r *Repo) Reset(target string, mode ResetMode, paths ...string) error
- func (r *Repo) ResolveRef(refname string) (Oid, error)
- func (r *Repo) RevParse(spec string) (Oid, error)
- func (r *Repo) Root() string
- func (r *Repo) Show(spec string) ([]byte, error)
- func (r *Repo) Stage(paths ...string) error
- func (r *Repo) StagedEntries() ([]StatusEntry, error)
- func (r *Repo) StashList() ([]StashEntry, error)
- func (r *Repo) StashPop(index int) error
- func (r *Repo) StashPush(message string) error
- func (r *Repo) Status() ([]StatusEntry, error)
- func (r *Repo) TrackingBranch(branch string) (string, error)
- func (r *Repo) TreeHash(revision, path string) (TreeHash, error)
- func (r *Repo) Unstage(paths ...string) error
- type Repository
- type ResetMode
- type Resetter
- type SignFormat
- type SignOptions
- type Signature
- type StashEntry
- type Stasher
- type StatusEntry
- type Tag
- type TreeEntry
- type TreeHash
- type TreeReader
Constants ¶
const ( FileAdded = model.FileAdded FileModified = model.FileModified FileDeleted = model.FileDeleted FileRenamed = model.FileRenamed FileCopied = model.FileCopied FileUntracked = model.FileUntracked FileIgnored = model.FileIgnored FileTypeChanged = model.FileTypeChanged FileConflicted = model.FileConflicted )
const ( Staged = model.Staged Unstaged = model.Unstaged Untracked = model.Untracked Conflicted = model.Conflicted )
const ( EntryKindBlob = model.EntryKindBlob EntryKindTree = model.EntryKindTree EntryKindSubmodule = model.EntryKindSubmodule )
const ( LocalBranches = model.LocalBranches RemoteBranches = model.RemoteBranches AllBranches = model.AllBranches )
const ( SignFormatDefault = model.SignFormatDefault SignFormatOpenPGP = model.SignFormatOpenPGP SignFormatSSH = model.SignFormatSSH SignFormatX509 = model.SignFormatX509 )
const ( ResetMixed = model.ResetMixed ResetSoft = model.ResetSoft ResetHard = model.ResetHard )
const (
DefaultBranch = model.DefaultBranch
)
Variables ¶
var ( WithPreferCLI = model.WithPreferCLI WithCLIPath = model.WithCLIPath WithTransport = model.WithTransport WithSigning = model.WithSigning WithExtraArgs = model.WithExtraArgs WithDiffContext = model.WithDiffContext WithDiffNameOnly = model.WithDiffNameOnly WithDiffExtraArgs = model.WithDiffExtraArgs WithLogExtraArgs = model.WithLogExtraArgs WithLineRange = model.WithLineRange WithIgnoreWhitespace = model.WithIgnoreWhitespace WithBlameExtraArgs = model.WithBlameExtraArgs WithCommitAuthor = model.WithCommitAuthor WithCommitCommitter = model.WithCommitCommitter WithCommitSign = model.WithCommitSign WithCommitAmend = model.WithCommitAmend WithCommitExtraArgs = model.WithCommitExtraArgs WithFetchPrune = model.WithFetchPrune WithFetchDepth = model.WithFetchDepth WithFetchRefspecs = model.WithFetchRefspecs WithFetchExtraArgs = model.WithFetchExtraArgs WithPushForce = model.WithPushForce WithPushRefspecs = model.WithPushRefspecs WithPushExtraArgs = model.WithPushExtraArgs WithDescribeMatch = model.WithDescribeMatch WithDescribeAnnotatedTagsOnly = model.WithDescribeAnnotatedTagsOnly WithDescribeLong = model.WithDescribeLong WithDescribeAbbreviated = model.WithDescribeAbbreviated WithDescribeAlways = model.WithDescribeAlways WithDescribeExtraArgs = model.WithDescribeExtraArgs WithGrepPathspecs = model.WithGrepPathspecs WithGrepIgnoreCase = model.WithGrepIgnoreCase WithGrepLineNumbers = model.WithGrepLineNumbers WithGrepExtraArgs = model.WithGrepExtraArgs WithMergeCommit = model.WithMergeCommit WithMergeFFOnly = model.WithMergeFFOnly WithMergeNoFastForward = model.WithMergeNoFastForward WithMergeSquash = model.WithMergeSquash WithMergeMessage = model.WithMergeMessage WithMergeExtraArgs = model.WithMergeExtraArgs WithRebaseInteractive = model.WithRebaseInteractive WithRebaseAutosquash = model.WithRebaseAutosquash WithRebaseExtraArgs = model.WithRebaseExtraArgs WithCherryPickMainline = model.WithCherryPickMainline WithCherryPickNoCommit = model.WithCherryPickNoCommit WithCherryPickExtraArgs = model.WithCherryPickExtraArgs WithCheckoutCreateBranch = model.WithCheckoutCreateBranch WithCheckoutForce = model.WithCheckoutForce WithCheckoutDetach = model.WithCheckoutDetach WithCheckoutExtraArgs = model.WithCheckoutExtraArgs WithCleanDirectories = model.WithCleanDirectories WithCleanIgnored = model.WithCleanIgnored WithCleanForce = model.WithCleanForce WithCleanExtraArgs = model.WithCleanExtraArgs )
Functions ¶
func ErrAlreadyExists ¶
func ErrAmbiguousRef ¶
func ErrCheckedOutBranch ¶
func ErrConfigNotFound ¶
func ErrConflict ¶
func ErrDetachedHead ¶
func ErrEmbeddedUnsupported ¶
func ErrFileTooLarge ¶
func ErrIdentityMissing ¶
func ErrInternal ¶
func ErrInvalidConfigKey ¶
func ErrInvalidLineRange ¶
func ErrInvalidPath ¶
func ErrInvalidTransport ¶
func ErrNetwork ¶
func ErrPushRejected ¶
func ErrRefNotFound ¶
func ErrRemoteAuth ¶
func ErrRemoteNotFound ¶
func ErrRepoNotFound ¶
func ErrSigningKeyMissing ¶
func ErrSigningNotSupported ¶
Types ¶
type BlameOption ¶
type BlameOption = model.BlameOption
type BlameOptions ¶
type BlameOptions = model.BlameOptions
type Blamer ¶
type Blamer interface {
// Blame returns line-level attribution for a file at a revision.
Blame(revision, path string, opts ...BlameOption) ([]BlameLine, error)
}
Blamer provides per-line commit attribution.
type BranchFilter ¶
type BranchFilter = model.BranchFilter
type Checker ¶
type Checker interface {
// Checkout updates HEAD, index, or paths to the requested target.
Checkout(target string, paths ...string) error
}
Checker provides checkout operations.
type CheckoutOption ¶
type CheckoutOption = model.CheckoutOption
type CheckoutOptions ¶
type CheckoutOptions = model.CheckoutOptions
type CherryPickOption ¶
type CherryPickOption = model.CherryPickOption
type CherryPickOptions ¶
type CherryPickOptions = model.CherryPickOptions
type CherryPicker ¶
type CherryPicker interface {
// CherryPick applies the given revision onto the current HEAD.
CherryPick(revision string) error
// CherryPickContinue continues an in-progress cherry-pick.
CherryPickContinue() error
// CherryPickAbort aborts an in-progress cherry-pick.
CherryPickAbort() error
}
CherryPicker provides cherry-pick operations.
type CleanOption ¶
type CleanOption = model.CleanOption
type CleanOptions ¶
type CleanOptions = model.CleanOptions
type CommitOption ¶
type CommitOption = model.CommitOption
type CommitOptions ¶
type CommitOptions = model.CommitOptions
type Committer ¶
type Committer interface {
// Commit creates a new commit from the current index state.
Commit(message string, opts ...CommitOption) (Oid, error)
}
Committer provides commit creation.
type ConfigReader ¶
type ConfigReader interface {
// ConfigGet gets the last configured value for a key.
ConfigGet(key string) (string, error)
// ConfigGetAll gets all configured values for a key.
ConfigGetAll(key string) ([]string, error)
// ConfigSet sets a config key to a single value.
ConfigSet(key, value string) error
}
ConfigReader provides git config access.
type DescribeOption ¶
type DescribeOption = model.DescribeOption
type DescribeOptions ¶
type DescribeOptions = model.DescribeOptions
type DiffOption ¶
type DiffOption = model.DiffOption
type DiffOptions ¶
type DiffOptions = model.DiffOptions
type Differ ¶
type Differ interface {
// Diff returns file changes between two refs (branches, tags, or SHAs).
Diff(from, to string) ([]DiffEntry, error)
// DiffStats returns aggregated statistics for changes between two refs.
DiffStats(from, to string) (DiffStats, error)
// Status returns the working tree status (staged, unstaged, untracked files).
Status() ([]StatusEntry, error)
}
Differ provides diff and working tree status operations.
type EntryState ¶
type EntryState = model.EntryState
type Executor ¶
type Executor interface {
// Exec runs the git CLI with the provided arguments in the repository root.
Exec(args ...string) ([]byte, error)
}
Executor provides a raw git command escape hatch.
type FetchOption ¶
type FetchOption = model.FetchOption
type FetchOptions ¶
type FetchOptions = model.FetchOptions
type FileStatus ¶
type FileStatus = model.FileStatus
type GrepOption ¶
type GrepOption = model.GrepOption
type GrepOptions ¶
type GrepOptions = model.GrepOptions
type IndexManager ¶
type IndexManager interface {
// Stage adds the provided paths to the repository index.
Stage(paths ...string) error
// Unstage removes paths from the index while preserving worktree changes.
Unstage(paths ...string) error
// StagedEntries returns staged files from the repository index.
StagedEntries() ([]StatusEntry, error)
}
IndexManager provides staging area operations.
type Inspector ¶
type Inspector interface {
// Describe resolves a human-readable name for a revision.
Describe(revision string) (string, error)
// RevParse resolves a revision expression to an object ID.
RevParse(spec string) (Oid, error)
// Grep searches tracked content for pattern matches.
Grep(pattern string, paths ...string) ([]GrepMatch, error)
// Show returns raw object or file content for a revision expression.
Show(spec string) ([]byte, error)
}
Inspector provides advanced read-only inspection helpers.
type LogOptions ¶
type LogOptions = model.LogOptions
type LogReader ¶
type LogReader interface {
// Log returns commits matching the supplied traversal options.
Log(opts LogOptions) ([]Commit, error)
// MergeBase returns a merge base for a and b.
MergeBase(a, b string) (Oid, error)
// IsAncestor reports whether a is an ancestor of b.
IsAncestor(a, b string) (bool, error)
}
LogReader provides commit log traversal.
type Maintainer ¶
type Maintainer interface {
// GC runs repository garbage collection.
GC() error
// Prune prunes unreachable repository data.
Prune() error
// Fsck verifies repository object integrity.
Fsck() error
// Clean lists or removes untracked files and returns their paths.
// By default it performs a dry-run (equivalent to git clean -n);
// no files are deleted unless WithCleanForce(true) is passed.
Clean(opts ...CleanOption) ([]string, error)
}
Maintainer provides repository maintenance operations.
type MergeOption ¶
type MergeOption = model.MergeOption
type MergeOptions ¶
type MergeOptions = model.MergeOptions
type MergeResult ¶
type MergeResult = model.MergeResult
type Merger ¶
type Merger interface {
// Merge merges the provided revision into the current HEAD.
Merge(revision string) error
// MergeAbort aborts an in-progress merge.
MergeAbort() error
}
Merger provides merge operations.
type OpenOptions ¶
type OpenOptions = model.OpenOptions
type PushOption ¶
type PushOption = model.PushOption
type PushOptions ¶
type PushOptions = model.PushOptions
type RebaseOption ¶
type RebaseOption = model.RebaseOption
type RebaseOptions ¶
type RebaseOptions = model.RebaseOptions
type RebaseResult ¶
type RebaseResult = model.RebaseResult
type Rebaser ¶
type Rebaser interface {
// Rebase rebases the current branch onto the provided revision.
Rebase(onto string) error
// RebaseContinue continues an in-progress rebase.
RebaseContinue() error
// RebaseAbort aborts an in-progress rebase.
RebaseAbort() error
}
Rebaser provides rebase operations.
type RefManager ¶
type RefManager interface {
// ListBranches lists repository branches matching filter.
ListBranches(filter BranchFilter) ([]Branch, error)
// ListTags lists repository tags.
ListTags() ([]Tag, error)
// CreateBranch creates a local branch at target.
CreateBranch(name, target string) error
// DeleteBranch deletes a local branch.
DeleteBranch(name string) error
// CreateTag creates a lightweight or annotated tag at target.
CreateTag(name, target, message string) error
// CreateSignedTag creates a signed annotated tag at target using the git CLI.
CreateSignedTag(name, target, message string, opts SignOptions) error
// DeleteTag deletes a tag.
DeleteTag(name string) error
}
RefManager provides branch and tag CRUD operations.
type RemoteManager ¶
type RemoteManager interface {
// ListRemotes lists configured remotes.
ListRemotes() ([]Remote, error)
// Fetch fetches updates from a remote. The context bounds the remote transfer.
Fetch(ctx context.Context, remote string, opts ...FetchOption) error
// Push pushes updates to a remote. The context bounds the remote transfer.
Push(ctx context.Context, remote string, opts ...PushOption) error
// TrackingBranch returns the configured upstream for a local branch.
TrackingBranch(branch string) (string, error)
}
RemoteManager provides remote repository operations.
type Repo ¶
type Repo struct {
// contains filtered or unexported fields
}
Repo orchestrates git operations across the available backends. Operations are routed to whichever backend implements them: - embedded (go-git): Repository, Diff, TreeRead, Log, Blame, Index, Commit, Ref, Remote, Config - cli (git binary): Exec, Inspect, Merge, Rebase, CherryPick, Reset, Stash, Maintain When preferCLI is true and a future CLI implementation covers an embedded operation, the CLI backend will be preferred for that operation.
func DiscoverWithAuth ¶
DiscoverWithAuth finds a git repository with explicit transport authentication.
func OpenWithAuth ¶
OpenWithAuth opens a git repository with explicit transport authentication.
func (*Repo) Blame ¶
func (r *Repo) Blame(revision, path string, opts ...BlameOption) ([]BlameLine, error)
func (*Repo) CherryPick ¶
func (*Repo) CherryPickAbort ¶
func (*Repo) CherryPickContinue ¶
func (*Repo) CreateBranch ¶
func (*Repo) CreateSignedTag ¶
func (r *Repo) CreateSignedTag(name, target, message string, opts SignOptions) error
func (*Repo) DeleteBranch ¶
func (*Repo) FileAtBounded ¶
func (*Repo) ListBranches ¶
func (r *Repo) ListBranches(filter BranchFilter) ([]Branch, error)
func (*Repo) ListRemotes ¶
func (*Repo) MergeAbort ¶
func (*Repo) RebaseAbort ¶
func (*Repo) RebaseContinue ¶
func (*Repo) StagedEntries ¶
func (r *Repo) StagedEntries() ([]StatusEntry, error)
func (*Repo) StashList ¶
func (r *Repo) StashList() ([]StashEntry, error)
func (*Repo) Status ¶
func (r *Repo) Status() ([]StatusEntry, error)
type Repository ¶
type Repository interface {
// Root returns the absolute path to the repository root.
Root() string
// Head returns the reference that HEAD points to.
Head() (Reference, error)
// ResolveRef resolves a ref name (branch, tag, or SHA prefix) to an OID.
ResolveRef(refname string) (Oid, error)
// IsDirty reports whether the working tree has uncommitted changes.
IsDirty() (bool, error)
}
Repository provides core git repository operations.
type Resetter ¶
type Resetter interface {
// Reset resets the repository to target using the requested mode.
Reset(target string, mode ResetMode, paths ...string) error
}
Resetter provides reset operations.
type SignFormat ¶
type SignFormat = model.SignFormat
type SignOptions ¶
type SignOptions = model.SignOptions
type StashEntry ¶
type StashEntry = model.StashEntry
type Stasher ¶
type Stasher interface {
// StashPush saves worktree and index state with an optional message.
StashPush(message string) error
// StashPop applies and drops the stash entry at index.
StashPop(index int) error
// StashList lists available stash entries.
StashList() ([]StashEntry, error)
}
Stasher provides stash operations.
type StatusEntry ¶
type StatusEntry = model.StatusEntry
type TreeReader ¶
type TreeReader interface {
// TreeHash returns the OID of the tree at the given path and revision.
TreeHash(revision, path string) (TreeHash, error)
// FileAt returns the content of a file at the given revision and path.
FileAt(revision, path string) ([]byte, error)
// FileAtBounded returns file content only when the blob fits maxBytes.
FileAtBounded(revision, path string, maxBytes int64) ([]byte, error)
// ListEntries returns the entries in a tree at the given revision and path.
ListEntries(revision, path string) ([]TreeEntry, error)
}
TreeReader provides read access to git tree objects.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package auth defines transport and signing configuration shared by git backends.
|
Package auth defines transport and signing configuration shared by git backends. |
|
Package cli provides a subprocess-backed git backend for operations that rely on native git command behavior, including exec, inspection, write, merge, reset, stash, and maintenance workflows.
|
Package cli provides a subprocess-backed git backend for operations that rely on native git command behavior, including exec, inspection, write, merge, reset, stash, and maintenance workflows. |
|
Package embedded provides the pure-Go go-git backend for the git module.
|
Package embedded provides the pure-Go go-git backend for the git module. |
|
internal
|
|
|
giterr
Package giterr defines the internal typed error values shared across the git packages.
|
Package giterr defines the internal typed error values shared across the git packages. |
|
model
Package model defines the internal value types shared across the git packages.
|
Package model defines the internal value types shared across the git packages. |
|
redact
Package redact masks sensitive material in git diagnostics so credentials never leak into error messages or logs.
|
Package redact masks sensitive material in git diagnostics so credentials never leak into error messages or logs. |