Documentation
¶
Overview ¶
internal/git/git.go
Index ¶
- Variables
- func AbbrevSHA(sha string) string
- type Commit
- type Git
- func (g *Git) BranchExists(branch string) bool
- func (g *Git) Checkout(branch string) error
- func (g *Git) Commit(message string) error
- func (g *Git) CommitExists(sha string) bool
- func (g *Git) CreateAndCheckout(name string) error
- func (g *Git) CreateBranch(name string) error
- func (g *Git) CreateBranchAt(name, sha string) error
- func (g *Git) CurrentBranch() (string, error)
- func (g *Git) DeleteBranch(branch string) error
- func (g *Git) FastForward(branch string) error
- func (g *Git) Fetch() error
- func (g *Git) GetCommits(base, head string) ([]Commit, error)
- func (g *Git) GetGitDir() string
- func (g *Git) GetMergeBase(a, b string) (string, error)
- func (g *Git) GetTip(branch string) (string, error)
- func (g *Git) HasStagedChanges() (bool, error)
- func (g *Git) HasUnmergedCommits(branch, upstream string) (bool, error)
- func (g *Git) IsContentMerged(branch, upstream string) (bool, error)
- func (g *Git) IsDirty() (bool, error)
- func (g *Git) IsRebaseInProgress() bool
- func (g *Git) NeedsRebase(branch, parent string) (bool, error)
- func (g *Git) Push(branch string, force bool) error
- func (g *Git) Rebase(onto string) error
- func (g *Git) RebaseAbort() error
- func (g *Git) RebaseContinue() error
- func (g *Git) RebaseOnto(newBase, oldBase, branch string) error
- func (g *Git) RemoteBranchExists(branch string) bool
- func (g *Git) SetBranchRef(branch, sha string) error
- func (g *Git) Stash(message string) (string, error)
- func (g *Git) StashList() (bool, error)
- func (g *Git) StashPop(ref string) error
Constants ¶
This section is empty.
Variables ¶
var ErrDirtyWorkTree = errors.New("working tree has uncommitted changes")
ErrDirtyWorkTree is returned when the working tree has uncommitted changes.
Functions ¶
Types ¶
type Commit ¶
type Commit struct {
Subject string // First line of the commit message
Body string // Everything after the first line (may be empty)
}
Commit represents a git commit with its subject and body.
type Git ¶
type Git struct {
// contains filtered or unexported fields
}
Git provides git operations for a repository.
func (*Git) BranchExists ¶
BranchExists checks if a branch exists.
func (*Git) CommitExists ¶
CommitExists checks if a commit SHA exists in the repository.
func (*Git) CreateAndCheckout ¶
CreateAndCheckout creates a new branch and switches to it.
func (*Git) CreateBranch ¶
CreateBranch creates a new branch at the current HEAD.
func (*Git) CreateBranchAt ¶ added in v0.2.0
CreateBranchAt creates a new branch at a specific SHA. This is equivalent to `git branch <name> <sha>`.
func (*Git) CurrentBranch ¶
CurrentBranch returns the name of the current branch.
func (*Git) DeleteBranch ¶
DeleteBranch deletes a local branch.
func (*Git) FastForward ¶
FastForward fast-forwards a branch to its remote tracking branch.
func (*Git) GetCommits ¶
GetCommits returns the commits from base..head (commits in head not in base). Returns commits in reverse chronological order (newest first).
func (*Git) GetMergeBase ¶
GetMergeBase returns the merge base of two branches.
func (*Git) HasStagedChanges ¶
HasStagedChanges returns true if there are staged changes.
func (*Git) HasUnmergedCommits ¶
HasUnmergedCommits returns true if the branch has commits not yet in upstream. Uses git cherry to detect by diff content, which works for cherry-picks where the commit SHAs differ but the content is the same. Note: This does NOT detect squash merges where multiple commits are combined. Use IsContentMerged for squash merge detection.
func (*Git) IsContentMerged ¶
IsContentMerged returns true if the branch has no content differences from upstream. This detects squash merges where the tree content is identical even though the commit history differs. Returns true if `git diff upstream branch` is empty.
func (*Git) IsRebaseInProgress ¶
IsRebaseInProgress checks if a rebase is in progress.
func (*Git) NeedsRebase ¶
NeedsRebase returns true if branch needs to be rebased onto parent.
func (*Git) RebaseAbort ¶
RebaseAbort aborts an in-progress rebase.
func (*Git) RebaseContinue ¶
RebaseContinue continues an in-progress rebase.
func (*Git) RebaseOnto ¶
RebaseOnto rebases a branch onto a new base, replaying only commits after oldBase. Checks out the branch first, then runs: git rebase --onto <newBase> <oldBase> Useful when a parent branch was squash-merged and we need to replay only the commits unique to the child branch.
func (*Git) RemoteBranchExists ¶
RemoteBranchExists checks if a branch exists on the remote (origin).
func (*Git) SetBranchRef ¶ added in v0.2.0
SetBranchRef sets a branch ref to point to a specific SHA. This is equivalent to `git branch -f <branch> <sha>`.
func (*Git) Stash ¶ added in v0.2.0
Stash creates a stash with the given message and returns the stash commit hash. Returns an empty string if there was nothing to stash. Includes untracked files (-u) to capture all working tree changes. The returned hash is stable and can be used to restore this specific stash even if other stashes are created later.
func (*Git) StashPop ¶ added in v0.2.0
StashPop restores a specific stash entry when a reference is provided. If ref is empty, it pops the most recent stash entry (matching `git stash pop`). When a commit hash is provided (from Stash()), uses apply+drop since pop only accepts stash refs. Returns an error if there are conflicts or no matching stash entry.