Documentation
¶
Index ¶
- func BranchExists(name string) bool
- func CheckoutBranch(name string) error
- func CherryPick(commits []string) error
- func CherryPickAbort()
- func CherryPickContinue() 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 DeleteTrackingRef(remote, branch string) error
- func DiffStatRange(base, head string) (additions, deletions int, err error)
- func EnableRerere() error
- func Fetch(remote string) error
- func FetchBranches(remote string, branches []string) error
- func GitDir() (string, error)
- func HasStagedChanges() bool
- func HasUncommittedChanges() (bool, error)
- 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, opts RebaseOpts) error
- func RebaseAbort() error
- func RebaseContinue(opts RebaseOpts) error
- func RebaseOnto(newBase, oldBase, branch string, opts RebaseOpts) error
- func RenameBranch(oldName, newName 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 RootDir() (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) CherryPick(commits []string) error
- func (m *MockOps) CherryPickAbort() error
- func (m *MockOps) CherryPickContinue() 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) DeleteTrackingRef(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) FetchBranches(remote string, branches []string) error
- func (m *MockOps) FindConflictMarkers(filePath string) (*ConflictMarkerInfo, error)
- func (m *MockOps) GitDir() (string, error)
- func (m *MockOps) HasStagedChanges() bool
- func (m *MockOps) HasUncommittedChanges() (bool, error)
- 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) LogMerges(base, head string) ([]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, opts RebaseOpts) error
- func (m *MockOps) RebaseAbort() error
- func (m *MockOps) RebaseContinue(opts RebaseOpts) error
- func (m *MockOps) RebaseOnto(newBase, oldBase, branch string, opts RebaseOpts) error
- func (m *MockOps) RenameBranch(oldName, newName 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) RootDir() (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
- type RebaseOpts
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 CherryPick ¶ added in v0.0.3
CherryPick applies the given commits to the current branch.
func CherryPickAbort ¶ added in v0.0.3
func CherryPickAbort()
CherryPickAbort clears any in-progress cherry-pick state. Errors are silently ignored (no-op if no cherry-pick is in progress).
func CherryPickContinue ¶ added in v0.0.3
func CherryPickContinue() error
CherryPickContinue continues an in-progress cherry-pick after conflicts are resolved.
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 DeleteTrackingRef ¶ added in v0.0.4
DeleteTrackingRef deletes a local remote-tracking ref (e.g. refs/remotes/origin/branch).
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 FetchBranches ¶ added in v0.0.3
FetchBranches fetches specific branches from a remote, updating their tracking refs.
func HasStagedChanges ¶
func HasStagedChanges() bool
HasStagedChanges returns true if there are staged changes ready to commit.
func HasUncommittedChanges ¶ added in v0.0.3
HasUncommittedChanges returns true if the working tree has uncommitted changes.
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 ¶
func Rebase(base string, opts RebaseOpts) error
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(opts RebaseOpts) 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 ¶
func RebaseOnto(newBase, oldBase, branch string, opts RebaseOpts) error
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 RenameBranch ¶ added in v0.0.3
RenameBranch renames a local branch.
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 LogMerges ¶ added in v0.0.3
func LogMerges(base, head string) ([]CommitInfo, error)
LogMerges returns merge commits in the range base..head.
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)
RootDirFn func() (string, error)
CurrentBranchFn func() (string, error)
BranchExistsFn func(string) bool
CheckoutBranchFn func(string) error
FetchFn func(string) error
FetchBranchesFn func(string, []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, RebaseOpts) error
EnableRerereFn func() error
IsRerereEnabledFn func() (bool, error)
IsRerereDeclinedFn func() (bool, error)
SaveRerereDeclinedFn func() error
RebaseOntoFn func(string, string, string, RebaseOpts) error
RebaseContinueFn func(RebaseOpts) 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
DeleteTrackingRefFn 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
RenameBranchFn func(string, string) error
CherryPickFn func([]string) error
HasUncommittedChangesFn func() (bool, error)
LogMergesFn func(string, string) ([]CommitInfo, 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) CherryPick ¶ added in v0.0.3
func (*MockOps) CherryPickAbort ¶ added in v0.0.3
func (*MockOps) CherryPickContinue ¶ added in v0.0.3
func (*MockOps) CommitInteractive ¶
func (*MockOps) ConflictedFiles ¶
func (*MockOps) CreateBranch ¶
func (*MockOps) CurrentBranch ¶
func (*MockOps) DefaultBranch ¶
func (*MockOps) DeleteRemoteBranch ¶
func (*MockOps) DeleteTrackingRef ¶ added in v0.0.4
func (*MockOps) DiffStatFiles ¶
func (m *MockOps) DiffStatFiles(base, head string) ([]FileDiffStat, error)
func (*MockOps) DiffStatRange ¶
func (*MockOps) EnableRerere ¶
func (*MockOps) FetchBranches ¶ added in v0.0.3
func (*MockOps) FindConflictMarkers ¶
func (m *MockOps) FindConflictMarkers(filePath string) (*ConflictMarkerInfo, error)
func (*MockOps) HasStagedChanges ¶
func (*MockOps) HasUncommittedChanges ¶ added in v0.0.3
func (*MockOps) IsAncestor ¶
func (*MockOps) IsRebaseInProgress ¶
func (*MockOps) IsRerereDeclined ¶
func (*MockOps) IsRerereEnabled ¶
func (*MockOps) LogMerges ¶ added in v0.0.3
func (m *MockOps) LogMerges(base, head string) ([]CommitInfo, error)
func (*MockOps) RebaseAbort ¶
func (*MockOps) RebaseContinue ¶
func (m *MockOps) RebaseContinue(opts RebaseOpts) error
func (*MockOps) RebaseOnto ¶
func (m *MockOps) RebaseOnto(newBase, oldBase, branch string, opts RebaseOpts) error
func (*MockOps) RenameBranch ¶ added in v0.0.3
func (*MockOps) SaveRerereDeclined ¶
func (*MockOps) SetUpstreamTracking ¶
func (*MockOps) StageTracked ¶
func (*MockOps) UpdateBranchRef ¶
func (*MockOps) ValidateRefName ¶
type Ops ¶
type Ops interface {
GitDir() (string, error)
RootDir() (string, error)
CurrentBranch() (string, error)
BranchExists(name string) bool
CheckoutBranch(name string) error
Fetch(remote string) error
FetchBranches(remote string, branches []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, opts RebaseOpts) error
EnableRerere() error
IsRerereEnabled() (bool, error)
IsRerereDeclined() (bool, error)
SaveRerereDeclined() error
RebaseOnto(newBase, oldBase, branch string, opts RebaseOpts) error
RebaseContinue(opts RebaseOpts) 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
DeleteTrackingRef(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
RenameBranch(oldName, newName string) error
CherryPick(commits []string) error
CherryPickAbort() error
CherryPickContinue() error
HasUncommittedChanges() (bool, error)
LogMerges(base, head string) ([]CommitInfo, 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().
type RebaseOpts ¶ added in v0.0.5
type RebaseOpts struct {
CommitterDateIsAuthorDate bool
}
RebaseOpts holds optional parameters for git rebase operations.