gitutil

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package gitutil holds helpers for interacting with git and with the Claude Code worktree layout (.claude/worktrees/<name>).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddWorktree

func AddWorktree(path, branch string) error

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 RepoRoot

func RepoRoot(stripClaudeWorktree bool) (string, error)

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

type Commit struct {
	Time    time.Time
	Subject string
}

Commit holds the bits of a git commit we display.

func LastCommit

func LastCommit(repoPath string) (Commit, error)

LastCommit returns the HEAD commit of the repository at repoPath.

type Worktree

type Worktree struct {
	Path   string
	Branch string // empty when HEAD is detached
}

Worktree is one entry from `git worktree list`.

func ListWorktrees

func ListWorktrees() ([]Worktree, error)

ListWorktrees parses `git worktree list --porcelain` and returns all registered worktrees (including the main one).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL