Documentation
¶
Index ¶
- func MirrorSubmodules(sourcePath, destPath string) error
- func ValidateBranchName(name string) error
- type Commit
- type Git
- func (g *Git) AddRemote(name, url string) error
- func (g *Git) BranchExists(branch string) bool
- func (g *Git) CheckoutBranch(branchName string) error
- func (g *Git) CreateBranchOnly(branchName, baseBranch string) error
- func (g *Git) CreateWorktree(branchName, worktreePath, baseBranch string) error
- func (g *Git) CreateWorktreeFromRemoteBranch(localBranch, worktreePath string) error
- func (g *Git) CurrentBranch() (string, error)
- func (g *Git) DeleteBranch(branchName string, force bool) error
- func (g *Git) Fetch() error
- func (g *Git) FetchRemote(remote string) error
- func (g *Git) FindAnyEzstackStash() (int, bool)
- func (g *Git) FindEzstackStash(branchName string) (int, bool)
- func (g *Git) FindRemoteByOwner(owner string) (string, string, error)
- func (g *Git) GetBranchCommit(branch string) (string, error)
- func (g *Git) GetCommitCount(base, head string) (int, error)
- func (g *Git) GetCommitsAhead(branch, target string) (int, error)
- func (g *Git) GetCommitsBehind(branch, target string) (int, error)
- func (g *Git) GetCommitsBetween(base, head string) ([]Commit, error)
- func (g *Git) GetDiffStat(base, head string) (added int, removed int, err error)
- func (g *Git) GetLastCommitMessage() (string, error)
- func (g *Git) GetMainWorktree() (string, error)
- func (g *Git) GetMergeBase(branch1, branch2 string) (string, error)
- func (g *Git) GetPRTemplate() string
- func (g *Git) GetRemote(name string) (string, error)
- func (g *Git) GetRepoRoot() (string, error)
- func (g *Git) HasChanges() (bool, error)
- func (g *Git) HasDivergedFromOrigin(branch string) (bool, int, int, error)
- func (g *Git) HasUnresolvedConflicts() (bool, error)
- func (g *Git) InitSubmodules(paths []string) error
- func (g *Git) IsBranchMerged(branch, target string) (bool, error)
- func (g *Git) IsLocalAheadOfOrigin(branch string) (bool, error)
- func (g *Git) IsLocalAheadOfRemote(branch string, remote string) (bool, error)
- func (g *Git) IsMergeInProgress() (bool, error)
- func (g *Git) IsRebaseInProgress() (bool, error)
- func (g *Git) ListInitializedSubmodules() ([]string, error)
- func (g *Git) ListLocalBranches() ([]string, error)
- func (g *Git) ListWorktrees() ([]Worktree, error)
- func (g *Git) Merge(target string) error
- func (g *Git) MergeContinue() error
- func (g *Git) MergeNonInteractive(target string) RebaseResult
- func (g *Git) PruneWorktrees() error
- func (g *Git) Push(force bool, remote ...string) error
- func (g *Git) PushBranch(branch string, force bool, remote ...string) error
- func (g *Git) PushForce(remote ...string) error
- func (g *Git) PushSetUpstream(remote ...string) error
- func (g *Git) Rebase(target string) error
- func (g *Git) RebaseContinue() error
- func (g *Git) RebaseNonInteractive(target string) RebaseResult
- func (g *Git) RebaseOntoNonInteractive(newBase, oldBase string) RebaseResult
- func (g *Git) RemoteBranchExists(branch string) bool
- func (g *Git) RemoveWorktree(worktreePath string, deleteBranch bool, branchName string) error
- func (g *Git) ResetHard(ref string) error
- func (g *Git) RunCapture(args ...string) (string, error)
- func (g *Git) RunInteractive(args ...string) error
- func (g *Git) StashPop() error
- func (g *Git) StashPopIndex(index int) error
- func (g *Git) StashPush() error
- type RebaseResult
- type Worktree
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MirrorSubmodules ¶ added in v4.6.0
MirrorSubmodules initializes in destPath the same submodules that are currently initialized in sourcePath. No-op when sourcePath has no initialized submodules. destPath must be a checked-out worktree of the same repository (submodules are per-worktree in Git).
func ValidateBranchName ¶
ValidateBranchName checks if a name is valid for a git branch.
Types ¶
type Git ¶
type Git struct {
RepoDir string
}
Git wraps git operations
func (*Git) BranchExists ¶
BranchExists checks if a local branch exists
func (*Git) CheckoutBranch ¶
CheckoutBranch switches to an existing branch
func (*Git) CreateBranchOnly ¶
CreateBranchOnly creates a new branch without a worktree
func (*Git) CreateWorktree ¶
CreateWorktree creates a new worktree
func (*Git) CreateWorktreeFromRemoteBranch ¶
CreateWorktreeFromRemoteBranch creates a worktree for a remote branch with tracking. If the local branch already exists (and has no worktree), it is force-updated to match the remote. The resulting local branch tracks origin/<localBranch>.
func (*Git) CurrentBranch ¶
CurrentBranch returns the current branch name
func (*Git) DeleteBranch ¶
DeleteBranch deletes a local git branch
func (*Git) FetchRemote ¶
FetchRemote fetches from a specific remote
func (*Git) FindAnyEzstackStash ¶
FindAnyEzstackStash returns the most recent stash entry tagged "ezstack-autostash" regardless of branch. Used only in the detached-HEAD fallback path where the current branch is unknown.
func (*Git) FindEzstackStash ¶
FindEzstackStash finds the stash index of an ezstack autostash entry for a specific branch. Git stash entries look like: "stash@{N}: On <branch>: ezstack-autostash" Returns (index, true) if found, (-1, false) if not found. Matches both branch name and message to avoid touching stashes from other worktrees.
func (*Git) FindRemoteByOwner ¶
FindRemoteByOwner finds a git remote that points to a repo owned by the given GitHub owner. Returns the remote name and URL, or empty strings if not found.
func (*Git) GetBranchCommit ¶
GetBranchCommit gets the commit hash of a branch
func (*Git) GetCommitCount ¶
GetCommitCount returns the number of commits between base and head This is useful to check if a branch has any commits of its own
func (*Git) GetCommitsAhead ¶
GetCommitsAhead returns the number of commits branch is ahead of target
func (*Git) GetCommitsBehind ¶
GetCommitsBehind returns the number of commits branch is behind target
func (*Git) GetCommitsBetween ¶
GetCommitsBetween returns commits between base and head (exclusive of base)
func (*Git) GetDiffStat ¶
GetDiffStat returns the total lines added and removed between base and head. Uses three-dot diff (merge-base) to show only changes introduced by head, not changes on base that head doesn't have.
func (*Git) GetLastCommitMessage ¶
GetLastCommitMessage returns the message of the last commit on the current branch
func (*Git) GetMainWorktree ¶
GetMainWorktree returns the path to the main worktree
func (*Git) GetMergeBase ¶
GetMergeBase finds the common ancestor between two branches
func (*Git) GetPRTemplate ¶
GetPRTemplate finds and reads the GitHub PR template from common locations. Returns the template content or empty string if no template is found. GitHub looks for templates in these locations (in order of priority): - .github/pull_request_template.md - .github/PULL_REQUEST_TEMPLATE.md - docs/pull_request_template.md - pull_request_template.md - PULL_REQUEST_TEMPLATE.md
func (*Git) GetRepoRoot ¶
GetRepoRoot returns the root directory of the git repository
func (*Git) HasChanges ¶
HasChanges returns true if the working directory has uncommitted changes
func (*Git) HasDivergedFromOrigin ¶
HasDivergedFromOrigin checks if local and remote branches have diverged Returns (hasDiverged, localAhead, remoteBehind, error) hasDiverged is true if both local has commits not in remote AND remote has commits not in local
func (*Git) HasUnresolvedConflicts ¶
HasUnresolvedConflicts checks if there are unresolved merge conflicts
func (*Git) InitSubmodules ¶ added in v4.6.0
InitSubmodules runs `git submodule update --init -- <paths>...` in g.RepoDir. Passing an empty paths slice is a no-op.
func (*Git) IsBranchMerged ¶
IsBranchMerged checks if a branch has been merged into target
func (*Git) IsLocalAheadOfOrigin ¶
IsLocalAheadOfOrigin checks if the local branch has commits not in origin. Deprecated: Use IsLocalAheadOfRemote instead.
func (*Git) IsLocalAheadOfRemote ¶
IsLocalAheadOfRemote checks if the local branch has commits not in the remote. If remote is empty, defaults to "origin". Returns true if local is ahead (needs push), false if in sync or behind.
func (*Git) IsMergeInProgress ¶
IsMergeInProgress checks if a merge is in progress
func (*Git) IsRebaseInProgress ¶
IsRebaseInProgress checks if a rebase is in progress
func (*Git) ListInitializedSubmodules ¶ added in v4.6.0
ListInitializedSubmodules returns the paths of submodules that are currently initialized in g.RepoDir. An empty slice is returned if the repo has no submodules or no submodules are initialized.
`git submodule status` output format:
<sha> <path> [(<desc>)] -> initialized and checked out -<sha> <path> -> not initialized +<sha> <path> [(<desc>)] -> initialized, SHA differs from recorded commit U<sha> <path> -> merge conflicts (treat as initialized)
We treat everything except '-' as initialized.
func (*Git) ListLocalBranches ¶
ListLocalBranches returns all local branch names
func (*Git) ListWorktrees ¶
ListWorktrees lists all worktrees
func (*Git) MergeContinue ¶
MergeContinue continues a merge in progress (commits the resolved merge)
func (*Git) MergeNonInteractive ¶
func (g *Git) MergeNonInteractive(target string) RebaseResult
MergeNonInteractive merges target into the current branch without interactive mode Returns structured result for conflict handling, matching RebaseResult for compatibility
func (*Git) PruneWorktrees ¶
PruneWorktrees prunes stale worktree metadata from git
func (*Git) Push ¶
Push pushes the current branch to the specified remote. If remote is empty, defaults to "origin".
func (*Git) PushBranch ¶
PushBranch pushes a specific branch to a remote (not necessarily the current branch). If remote is empty, defaults to "origin".
func (*Git) PushForce ¶
PushForce force pushes the current branch with lease (safer than --force). If remote is empty, defaults to "origin".
func (*Git) PushSetUpstream ¶
PushSetUpstream pushes and sets upstream. If remote is empty, defaults to "origin".
func (*Git) RebaseContinue ¶
RebaseContinue continues a rebase in progress
func (*Git) RebaseNonInteractive ¶
func (g *Git) RebaseNonInteractive(target string) RebaseResult
RebaseNonInteractive rebases current branch onto target without interactive mode Returns structured result instead of just error for better conflict handling
func (*Git) RebaseOntoNonInteractive ¶
func (g *Git) RebaseOntoNonInteractive(newBase, oldBase string) RebaseResult
RebaseOntoNonInteractive rebases commits from oldBase to current onto newBase Returns structured result for better conflict handling
func (*Git) RemoteBranchExists ¶
RemoteBranchExists checks if a remote branch exists
func (*Git) RemoveWorktree ¶
RemoveWorktree removes a worktree and optionally deletes the branch
func (*Git) ResetHard ¶
ResetHard performs a hard reset to the given ref This is used to fast-forward a branch that has no commits of its own
func (*Git) RunCapture ¶
run executes a git command and returns the output RunCapture executes a git command and returns stdout.
func (*Git) RunInteractive ¶
RunInteractive runs a git command interactively (for rebase with conflicts)
func (*Git) StashPop ¶
StashPop pops the ezstack autostash entry for the current branch. Uses targeted lookup to avoid popping user stashes or stashes from other branches. Returns nil if no ezstack stash is found (nothing to pop).
func (*Git) StashPopIndex ¶
StashPopIndex pops a specific stash entry by index.
type RebaseResult ¶
RebaseResult contains the result of a rebase operation