Documentation
¶
Overview ¶
Package gitutil holds helpers for interacting with git and with the Claude Code worktree layout (.claude/worktrees/<name>).
Index ¶
- func AddWorktree(path, branch string) error
- func CurrentClaudeWorktree() (path, name string, err error)
- func DeleteBranch(branch string, force bool) error
- func PruneWorktrees() error
- func RemoveWorktree(path string) error
- func RepoRoot(stripClaudeWorktree bool) (string, error)
- type Commit
- type Worktree
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddWorktree ¶
AddWorktree creates a new linked worktree at `path` on a freshly-created branch `branch`, via `git worktree add -b <branch> <path>`. On success the command is silent — git's progress chatter ("Preparing worktree…", "HEAD is now at…") is captured and discarded. On failure the captured output is written verbatim to the process stderr so the user sees git's own error message.
func CurrentClaudeWorktree ¶ added in v0.3.0
CurrentClaudeWorktree returns the path and name of the Claude Code worktree that contains the git toplevel of the current working directory, or ("", "", nil) if the toplevel isn't shaped like .../.claude/worktrees/<name>. An error is returned only if `git rev-parse --show-toplevel` itself fails.
func DeleteBranch ¶ added in v0.4.0
DeleteBranch deletes a local branch. Without force, `git branch -d` is used, which refuses to delete an unmerged branch; with force, `-D` force-deletes. A branch that doesn't exist is treated as success so the caller can re-invoke after a partial deletion without surfacing an error.
func PruneWorktrees ¶ added in v0.4.0
func PruneWorktrees() error
PruneWorktrees runs `git worktree prune` to clean up stale registrations (worktree entries whose on-disk directory no longer exists).
func RemoveWorktree ¶ added in v0.4.0
RemoveWorktree removes the linked worktree at path via `git worktree remove --force <path>`. --force is used so a worktree with local modifications still gets removed. If the path is not a registered worktree (already gone), nil is returned — making the operation idempotent.
func RepoRoot ¶
RepoRoot runs `git rev-parse --show-toplevel` and returns the resulting path with its trailing newline trimmed. Git's stderr is passed through to the process stderr so the caller's user sees `fatal: not a git repository` and similar messages.
If stripClaudeWorktree is true and the toplevel sits inside a Claude Code worktree (`.claude/worktrees/<name>`), the enclosing repository root is returned instead.
Types ¶
type Commit ¶
Commit holds the bits of a git commit we display.
func LastCommit ¶
LastCommit returns the HEAD commit of the repository at repoPath.
type Worktree ¶
Worktree is one entry from `git worktree list`.
func ListWorktrees ¶
ListWorktrees parses `git worktree list --porcelain` and returns all registered worktrees (including the main one).