Documentation
¶
Index ¶
- func ExecPath(ctx context.Context) (string, error)
- type Client
- func (c *Client) AbortMerge(ctx context.Context) error
- func (c *Client) Authors() ([]string, error)
- func (c *Client) Checkout(ctx context.Context, branchName string) error
- func (c *Client) Commit(ctx context.Context, msg []byte, opts CommitOptions) error
- func (c *Client) CreateBranch(name, baseBranch string) error
- func (c *Client) CreateWorktree(ctx context.Context, branchName, baseBranch, path string) error
- func (c *Client) CurrentBranch() (string, error)
- func (c *Client) DefaultBaseBranch() (string, error)
- func (c *Client) DeleteLocalBranch(ctx context.Context, name string, force bool) error
- func (c *Client) FastForwardOnly(ctx context.Context, sourceBranch, targetBranch string) error
- func (c *Client) Fetch(ctx context.Context) error
- func (c *Client) IO() *pkg.IO
- func (c *Client) IsAncestor(ctx context.Context, child, ancestor string) (bool, error)
- func (c *Client) IsDirty(ctx context.Context) (bool, error)
- func (c *Client) IsMergedInto(branchName, baseBranch string) (bool, error)
- func (c *Client) LocalBranchNames() ([]string, error)
- func (c *Client) MergeDryRun(ctx context.Context, branchName, baseBranch string) ([]string, error)
- func (c *Client) MergeNoFFNoCommit(ctx context.Context, featureBranch, baseBranch string) error
- func (c *Client) MergeRebase(ctx context.Context, featureBranch, baseBranch string) error
- func (c *Client) MergeSquash(ctx context.Context, branchName, baseBranch string) error
- func (c *Client) Remote() (string, error)
- func (c *Client) RepoName() (string, error)
- func (c *Client) ResetHard(ctx context.Context, target string) error
- func (c *Client) ResolveRef(name string) (plumbing.Hash, error)
- func (c *Client) SetRemote(name string)
- func (c *Client) WorkingTreeRoot() (string, error)
- type CommitOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps a go-git repository and exposes commit operations.
func NewClient ¶
NewClient opens the git repository that contains the current directory. ioStreams configures the streams used for interactive operations; nil uses os.Stdin/Stdout/Stderr.
func NewClientAt ¶ added in v0.4.2
NewClientAt opens the git repository rooted at dir. ioStreams configures the streams used for interactive operations; nil uses os.Stdin/Stdout/Stderr.
func (*Client) AbortMerge ¶ added in v0.9.3
AbortMerge runs `git merge --abort`. Used after a TUI abort or commit failure in the Classic close flow to clear MERGE_HEAD / MERGE_MSG and restore the working tree. Returns a wrapped error so callers can decide whether to treat a no-active-merge failure as fatal (e.g. by ignoring it when the orchestrator isn't sure whether MergeNoFFNoCommit actually started a merge).
func (*Client) Authors ¶
Authors returns a deduplicated, alphabetically sorted list of commit author strings ("Name <email>") from the repository history. The current git config identity is prepended as the first (default) entry.
func (*Client) Checkout ¶ added in v0.8.0
Checkout switches the working tree to branchName. Wraps `git checkout <name>`. Idempotent: when the working tree is already on branchName, the call is a no-op — the underlying `git checkout` is skipped so heavyweight `post-checkout` hooks don't fire for a same-branch "switch". Returns a wrapped error from the git CLI on failure (e.g. unknown branch, untracked file collision).
func (*Client) Commit ¶
Commit records a commit with msg and the given options using the system git binary so that all configured hooks (pre-commit, commit-msg, post-commit) run.
func (*Client) CreateBranch ¶
CreateBranch creates a new branch from baseBranch and checks it out.
func (*Client) CreateWorktree ¶ added in v0.9.0
CreateWorktree creates a new branch from baseBranch and checks it out in a linked worktree at path. Wraps `git worktree add -b <branch> <path> <base>`.
func (*Client) CurrentBranch ¶ added in v0.4.2
CurrentBranch returns the short name of the branch HEAD points to. On a detached HEAD the returned name will not parse as an issue branch, so callers can simply ignore it.
func (*Client) DefaultBaseBranch ¶
DefaultBaseBranch resolves the default base branch in priority order:
- refs/remotes/<remote>/HEAD (skipped when no remote)
- "main" if the local ref exists
- "master" if the local ref exists
func (*Client) DeleteLocalBranch ¶ added in v0.4.2
DeleteLocalBranch deletes the local branch by name. force=true uses -D (required after squash merges); force=false uses -d (safe).
func (*Client) FastForwardOnly ¶ added in v0.8.0
FastForwardOnly checks out targetBranch and runs `git merge --ff-only sourceBranch`. Returns a wrapped error when the FF is refused (diverged history) so the caller can render an actionable message.
func (*Client) Fetch ¶ added in v0.9.0
Fetch runs `git fetch <remote>`. Returns nil immediately when no remote is configured (local-only repo). Returns a wrapped error when the remote is unreachable or auth fails.
func (*Client) IO ¶ added in v0.8.0
IO returns the injected IO streams. Callers should write status/diagnostic messages through these instead of os.Stdout/os.Stderr so Cobra-aware redirection (tests, subcommand piping, future TUI capture) keeps working.
func (*Client) IsAncestor ¶ added in v0.8.0
IsAncestor reports whether child is an ancestor of ancestor (or equal). Wraps `git merge-base --is-ancestor child ancestor`: exit code 0 → true, exit code 1 → false, any other exit code → wrapped error.
func (*Client) IsDirty ¶ added in v0.8.0
IsDirty reports whether the working tree has tracked-file modifications or staged-but-uncommitted changes. Wraps `git status --porcelain --untracked-files=no`. Untracked files are intentionally NOT counted as dirty: `git reset --hard` does not touch untracked content, so their presence does not put user work at risk during rollback.
func (*Client) IsMergedInto ¶
IsMergedInto reports whether branchName's tip commit is reachable from baseBranch, i.e. whether the branch has been merged into base (mirrors git merge-base --is-ancestor).
func (*Client) LocalBranchNames ¶
LocalBranchNames returns the short names of all local branches.
func (*Client) MergeDryRun ¶ added in v0.4.2
MergeDryRun checks whether branchName merges cleanly into baseBranch. It uses `git merge-tree --write-tree` (git 2.38+) to perform a 3-way merge in-memory: the working tree is never touched, no hooks run, and submodules are not traversed. Returns the list of conflicting file paths, or nil if clean.
func (*Client) MergeNoFFNoCommit ¶ added in v0.9.3
MergeNoFFNoCommit checks out baseBranch and runs `git merge --no-ff --no-commit <featureBranch>`. Leaves MERGE_HEAD + MERGE_MSG in place so the caller can drive the commit step itself (typically via the commitizen TUI form). Caller is responsible for `git merge --abort` on TUI abort or commit failure.
func (*Client) MergeRebase ¶ added in v0.8.0
MergeRebase prepares featureBranch for a single-commit close. When a remote is configured, it merges against remote/<baseBranch> and soft-resets to the same ref. When no remote is available (local-only repo), it uses the local baseBranch directly.
The mechanic is a real `git merge --no-edit <remoteBase>` (submodule-safe — handles gitlinks correctly, unlike `merge --squash`) followed by `git reset --soft <remoteBase>`, leaving HEAD at <remoteBase>, the working tree at the merged state, and the index staged with the consolidated diff. The transient merge commit produced by the merge step is unreachable after the reset and is eventually garbage-collected — `--no-edit` is what prevents git from opening $EDITOR for that throwaway commit message.
Caller is responsible for the final commit (typically via the commitizen TUI form) and for rollback on failure.
func (*Client) MergeSquash ¶ added in v0.4.2
MergeSquash checks out baseBranch and squash-merges branchName into it, leaving the squashed changes staged. The caller is responsible for the follow-up commit (so it can drive an interactive commit form).
func (*Client) Remote ¶ added in v0.9.0
Remote returns the resolved remote name, auto-detecting on first call.
Resolution order:
- Already pinned via SetRemote → return as-is.
- Exactly one remote → cache and return its name.
- Zero remotes → return ("", nil); caller treats this as local-only.
- Multiple remotes, one named "origin" → use "origin" (git convention).
- Multiple remotes, none named "origin" → error with actionable message.
func (*Client) RepoName ¶ added in v0.9.0
RepoName returns a short identifier for this repository. Resolution order:
- Last path segment of the configured remote URL, with ".git" stripped.
- Base name of the working tree root directory (local-only fallback).
func (*Client) ResetHard ¶ added in v0.8.0
ResetHard runs `git reset --hard <target>`. Used by the close orchestrator to atomically roll the current branch back to its original tip on TUI abort or commit failure. Does not touch untracked files.
func (*Client) ResolveRef ¶ added in v0.8.0
ResolveRef returns the commit hash that `name` resolves to (with reference indirection followed). Use it for read-only ref lookups from packages that need a plumbing.Hash without taking a dependency on go-git's plumbing API.
func (*Client) SetRemote ¶ added in v0.9.0
SetRemote pins the remote name used for all remote operations. Call this when the user has configured branch.remote explicitly.
func (*Client) WorkingTreeRoot ¶
WorkingTreeRoot returns the absolute path of the repository's working tree root.