Documentation
¶
Index ¶
- func BranchExists(name string) bool
- func CheckoutBranch(name string) error
- func Commit(message string) (string, error)
- func CommitInteractive() (string, error)
- func ConflictedFiles() ([]string, error)
- func CreateBranch(name, base string) error
- func CurrentBranch() (string, error)
- func DefaultBranch() (string, error)
- func DeleteBranch(name string, force bool) error
- func DeleteRemoteBranch(remote, branch string) error
- func DiffStatRange(base, head string) (additions, deletions int, err error)
- func EnableRerere() error
- func Fetch(remote string) error
- func GitDir() (string, error)
- func HasStagedChanges() bool
- func IsAncestor(ancestor, descendant string) (bool, error)
- func IsRebaseInProgress() bool
- func IsRerereDeclined() (bool, error)
- func IsRerereEnabled() (bool, error)
- func MergeBase(a, b string) (string, error)
- func MergeFF(target string) error
- func Push(remote string, branches []string, force, atomic bool) error
- func Rebase(base string) error
- func RebaseAbort() error
- func RebaseContinue() error
- func RebaseOnto(newBase, oldBase, branch string) error
- func ResetHard(ref string) error
- func ResolveRemote(branch string) (string, error)
- func RevParse(ref string) (string, error)
- func RevParseMap(refs []string) (map[string]string, error)
- func RevParseMulti(refs []string) ([]string, error)
- func SaveRerereDeclined() error
- func SetOps(o Ops) func()
- func SetUpstreamTracking(branch, remote string) error
- func StageAll() error
- func StageTracked() error
- func UpdateBranchRef(branch, sha string) error
- func ValidateRefName(name string) error
- type CommitInfo
- type ConflictMarkerInfo
- type ConflictSection
- type ErrMultipleRemotes
- type FileDiffStat
- type MockOps
- func (m *MockOps) BranchExists(name string) bool
- func (m *MockOps) CheckoutBranch(name string) error
- func (m *MockOps) Commit(message string) (string, error)
- func (m *MockOps) CommitInteractive() (string, error)
- func (m *MockOps) ConflictedFiles() ([]string, error)
- func (m *MockOps) CreateBranch(name, base string) error
- func (m *MockOps) CurrentBranch() (string, error)
- func (m *MockOps) DefaultBranch() (string, error)
- func (m *MockOps) DeleteBranch(name string, force bool) error
- func (m *MockOps) DeleteRemoteBranch(remote, branch string) error
- func (m *MockOps) DiffStatFiles(base, head string) ([]FileDiffStat, error)
- func (m *MockOps) DiffStatRange(base, head string) (int, int, error)
- func (m *MockOps) EnableRerere() error
- func (m *MockOps) Fetch(remote string) error
- func (m *MockOps) FindConflictMarkers(filePath string) (*ConflictMarkerInfo, error)
- func (m *MockOps) GitDir() (string, error)
- func (m *MockOps) HasStagedChanges() bool
- func (m *MockOps) IsAncestor(ancestor, descendant string) (bool, error)
- func (m *MockOps) IsRebaseInProgress() bool
- func (m *MockOps) IsRerereDeclined() (bool, error)
- func (m *MockOps) IsRerereEnabled() (bool, error)
- func (m *MockOps) Log(ref string, maxCount int) ([]CommitInfo, error)
- func (m *MockOps) LogRange(base, head string) ([]CommitInfo, error)
- func (m *MockOps) MergeBase(a, b string) (string, error)
- func (m *MockOps) MergeFF(target string) error
- func (m *MockOps) Push(remote string, branches []string, force, atomic bool) error
- func (m *MockOps) Rebase(base string) error
- func (m *MockOps) RebaseAbort() error
- func (m *MockOps) RebaseContinue() error
- func (m *MockOps) RebaseOnto(newBase, oldBase, branch string) error
- func (m *MockOps) ResetHard(ref string) error
- func (m *MockOps) ResolveRemote(branch string) (string, error)
- func (m *MockOps) RevParse(ref string) (string, error)
- func (m *MockOps) RevParseMulti(refs []string) ([]string, error)
- func (m *MockOps) SaveRerereDeclined() error
- func (m *MockOps) SetUpstreamTracking(branch, remote string) error
- func (m *MockOps) StageAll() error
- func (m *MockOps) StageTracked() error
- func (m *MockOps) UpdateBranchRef(branch, sha string) error
- func (m *MockOps) ValidateRefName(name string) error
- type Ops
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BranchExists ¶
BranchExists returns whether a local branch with the given name exists.
func CheckoutBranch ¶
CheckoutBranch switches to the specified branch.
func CommitInteractive ¶
CommitInteractive launches the user's configured editor for the commit message, equivalent to running `git commit` without `-m`.
func ConflictedFiles ¶
ConflictedFiles returns the list of files that have merge conflicts.
func CreateBranch ¶
CreateBranch creates a new branch from the given base.
func CurrentBranch ¶
CurrentBranch returns the name of the current branch.
func DefaultBranch ¶
DefaultBranch returns the HEAD branch from origin.
func DeleteBranch ¶
DeleteBranch deletes a local branch.
func DeleteRemoteBranch ¶
DeleteRemoteBranch deletes a branch on the remote.
func DiffStatRange ¶
DiffStatRange returns the total additions and deletions between two refs.
func EnableRerere ¶
func EnableRerere() error
EnableRerere enables git rerere (reuse recorded resolution) and rerere.autoupdate (auto-stage resolved files) for the repository.
func HasStagedChanges ¶
func HasStagedChanges() bool
HasStagedChanges returns true if there are staged changes ready to commit.
func IsAncestor ¶
IsAncestor returns whether ancestor is an ancestor of descendant. This is useful to check if a fast-forward merge is possible.
func IsRebaseInProgress ¶
func IsRebaseInProgress() bool
IsRebaseInProgress checks whether a rebase is currently in progress.
func IsRerereDeclined ¶
IsRerereDeclined returns whether the user previously declined the rerere prompt.
func IsRerereEnabled ¶
IsRerereEnabled returns whether rerere.enabled is set to "true" in git config.
func Rebase ¶
Rebase rebases the current branch onto the given base. If rerere resolves all conflicts automatically, the rebase continues without user intervention.
func RebaseContinue ¶
func RebaseContinue() error
RebaseContinue continues an in-progress rebase. It sets GIT_EDITOR=true to prevent git from opening an interactive editor for the commit message, which would cause the command to hang. If rerere resolves subsequent conflicts automatically, the rebase continues without user intervention.
func RebaseOnto ¶
RebaseOnto rebases a branch using the three-argument form:
git rebase --onto <newBase> <oldBase> <branch>
This replays commits after oldBase from branch onto newBase. It is used when a prior branch was merged and the normal rebase cannot detect which commits have already been applied. If rerere resolves all conflicts automatically, the rebase continues without user intervention.
func ResolveRemote ¶
ResolveRemote determines the remote for pushing a branch. Checks git config in priority order, falls back to listing remotes. Returns *ErrMultipleRemotes if multiple remotes exist with no configured default.
func RevParseMap ¶
RevParseMap resolves multiple refs and returns a ref→SHA map.
func RevParseMulti ¶
RevParseMulti resolves multiple refs to their full SHAs in a single git rev-parse invocation. Returns SHAs in the same order as the input refs.
func SaveRerereDeclined ¶
func SaveRerereDeclined() error
SaveRerereDeclined records that the user declined the rerere prompt.
func SetOps ¶
func SetOps(o Ops) func()
SetOps replaces the git operations implementation. Returns a restore function.
func SetUpstreamTracking ¶
SetUpstreamTracking sets the upstream tracking branch.
func StageAll ¶
func StageAll() error
StageAll stages all changes including untracked files (git add -A).
func StageTracked ¶
func StageTracked() error
StageTracked stages changes to tracked files only (git add -u).
func UpdateBranchRef ¶
UpdateBranchRef moves a branch pointer to a new commit (for branches not currently checked out).
func ValidateRefName ¶
ValidateRefName checks whether name is a valid git branch name.
Types ¶
type CommitInfo ¶
CommitInfo holds metadata about a single commit.
func Log ¶
func Log(ref string, maxCount int) ([]CommitInfo, error)
Log returns recent commits for the given branch.
func LogRange ¶
func LogRange(base, head string) ([]CommitInfo, error)
LogRange returns commits in the range base..head (commits reachable from head but not from base). This is useful for seeing all commits unique to a branch.
type ConflictMarkerInfo ¶
type ConflictMarkerInfo struct {
File string
Sections []ConflictSection
}
ConflictMarkerInfo holds the location of conflict markers in a file.
func FindConflictMarkers ¶
func FindConflictMarkers(filePath string) (*ConflictMarkerInfo, error)
FindConflictMarkers scans a file for conflict markers and returns their locations.
type ConflictSection ¶
type ConflictSection struct {
StartLine int // line number of <<<<<<<
EndLine int // line number of >>>>>>>
}
ConflictSection represents a single conflict hunk in a file.
type ErrMultipleRemotes ¶
type ErrMultipleRemotes struct {
Remotes []string
}
ErrMultipleRemotes is returned by ResolveRemote when multiple remotes are configured and none is designated as the push target.
func (*ErrMultipleRemotes) Error ¶
func (e *ErrMultipleRemotes) Error() string
type FileDiffStat ¶
FileDiffStat holds per-file diff statistics.
func DiffStatFiles ¶
func DiffStatFiles(base, head string) ([]FileDiffStat, error)
DiffStatFiles returns per-file additions and deletions between two refs.
type MockOps ¶
type MockOps struct {
GitDirFn func() (string, error)
CurrentBranchFn func() (string, error)
BranchExistsFn func(string) bool
CheckoutBranchFn func(string) error
FetchFn func(string) error
DefaultBranchFn func() (string, error)
CreateBranchFn func(string, string) error
PushFn func(string, []string, bool, bool) error
ResolveRemoteFn func(string) (string, error)
RebaseFn func(string) error
EnableRerereFn func() error
IsRerereEnabledFn func() (bool, error)
IsRerereDeclinedFn func() (bool, error)
SaveRerereDeclinedFn func() error
RebaseOntoFn func(string, string, string) error
RebaseContinueFn func() error
RebaseAbortFn func() error
IsRebaseInProgressFn func() bool
ConflictedFilesFn func() ([]string, error)
FindConflictMarkersFn func(string) (*ConflictMarkerInfo, error)
IsAncestorFn func(string, string) (bool, error)
RevParseFn func(string) (string, error)
RevParseMultiFn func([]string) ([]string, error)
MergeBaseFn func(string, string) (string, error)
LogFn func(string, int) ([]CommitInfo, error)
LogRangeFn func(string, string) ([]CommitInfo, error)
DiffStatRangeFn func(string, string) (int, int, error)
DiffStatFilesFn func(string, string) ([]FileDiffStat, error)
DeleteBranchFn func(string, bool) error
DeleteRemoteBranchFn func(string, string) error
ResetHardFn func(string) error
SetUpstreamTrackingFn func(string, string) error
MergeFFFn func(string) error
UpdateBranchRefFn func(string, string) error
StageAllFn func() error
StageTrackedFn func() error
HasStagedChangesFn func() bool
CommitFn func(string) (string, error)
CommitInteractiveFn func() (string, error)
ValidateRefNameFn func(string) error
}
MockOps is a test double for git operations. Each field is an optional function that, when set, handles the corresponding Ops method call. When nil, a reasonable default is returned.
func (*MockOps) BranchExists ¶
func (*MockOps) CheckoutBranch ¶
func (*MockOps) CommitInteractive ¶
func (*MockOps) ConflictedFiles ¶
func (*MockOps) CreateBranch ¶
func (*MockOps) CurrentBranch ¶
func (*MockOps) DefaultBranch ¶
func (*MockOps) DeleteRemoteBranch ¶
func (*MockOps) DiffStatFiles ¶
func (m *MockOps) DiffStatFiles(base, head string) ([]FileDiffStat, error)
func (*MockOps) DiffStatRange ¶
func (*MockOps) EnableRerere ¶
func (*MockOps) FindConflictMarkers ¶
func (m *MockOps) FindConflictMarkers(filePath string) (*ConflictMarkerInfo, error)
func (*MockOps) HasStagedChanges ¶
func (*MockOps) IsAncestor ¶
func (*MockOps) IsRebaseInProgress ¶
func (*MockOps) IsRerereDeclined ¶
func (*MockOps) IsRerereEnabled ¶
func (*MockOps) RebaseAbort ¶
func (*MockOps) RebaseContinue ¶
func (*MockOps) RebaseOnto ¶
func (*MockOps) SaveRerereDeclined ¶
func (*MockOps) SetUpstreamTracking ¶
func (*MockOps) StageTracked ¶
func (*MockOps) UpdateBranchRef ¶
func (*MockOps) ValidateRefName ¶
type Ops ¶
type Ops interface {
GitDir() (string, error)
CurrentBranch() (string, error)
BranchExists(name string) bool
CheckoutBranch(name string) error
Fetch(remote string) error
DefaultBranch() (string, error)
CreateBranch(name, base string) error
Push(remote string, branches []string, force, atomic bool) error
ResolveRemote(branch string) (string, error)
Rebase(base string) error
EnableRerere() error
IsRerereEnabled() (bool, error)
IsRerereDeclined() (bool, error)
SaveRerereDeclined() error
RebaseOnto(newBase, oldBase, branch string) error
RebaseContinue() error
RebaseAbort() error
IsRebaseInProgress() bool
ConflictedFiles() ([]string, error)
FindConflictMarkers(filePath string) (*ConflictMarkerInfo, error)
IsAncestor(ancestor, descendant string) (bool, error)
RevParse(ref string) (string, error)
RevParseMulti(refs []string) ([]string, error)
MergeBase(a, b string) (string, error)
Log(ref string, maxCount int) ([]CommitInfo, error)
LogRange(base, head string) ([]CommitInfo, error)
DiffStatRange(base, head string) (additions, deletions int, err error)
DiffStatFiles(base, head string) ([]FileDiffStat, error)
DeleteBranch(name string, force bool) error
DeleteRemoteBranch(remote, branch string) error
ResetHard(ref string) error
SetUpstreamTracking(branch, remote string) error
MergeFF(target string) error
UpdateBranchRef(branch, sha string) error
StageAll() error
StageTracked() error
HasStagedChanges() bool
Commit(message string) (string, error)
CommitInteractive() (string, error)
ValidateRefName(name string) error
}
Ops defines the interface for git operations used by commands. The package-level functions are the default production implementation. Tests can substitute a mock via SetOps().