git

package
v0.54.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetGitCommonDir

func GetGitCommonDir() (string, error)

GetGitCommonDir returns the common git directory shared across all worktrees. For regular repos, this equals GetGitDir(). For worktrees, this returns the main repository's .git directory where shared data (like worktree registrations, hooks, and objects) lives.

Use this instead of GetGitDir() when you need to create new worktrees or access shared git data that should not be scoped to a single worktree. GH#639: This is critical for bare repo setups where GetGitDir() returns a worktree-specific path that cannot host new worktrees.

func GetGitDir

func GetGitDir() (string, error)

GetGitDir returns the actual .git directory path for the current repository. In a normal repo, this is ".git". In a worktree, .git is a file containing "gitdir: /path/to/actual/git/dir", so we use git rev-parse.

This function uses Git's native worktree-aware APIs and should be used instead of direct filepath.Join(path, ".git") throughout the codebase.

func GetGitHeadPath

func GetGitHeadPath() (string, error)

GetGitHeadPath returns the path to the Git HEAD file. This function is worktree-aware and handles both regular repos and worktrees.

func GetGitHooksDir

func GetGitHooksDir() (string, error)

GetGitHooksDir returns the path to the Git hooks directory. This function is worktree-aware and handles both regular repos and worktrees.

func GetGitRefsDir

func GetGitRefsDir() (string, error)

GetGitRefsDir returns the path to the Git refs directory. This function is worktree-aware and handles both regular repos and worktrees.

func GetMainRepoRoot

func GetMainRepoRoot() (string, error)

GetMainRepoRoot returns the main repository root directory. When in a worktree, this returns the main repository root. Otherwise, it returns the regular repository root.

For nested worktrees (worktrees located under the main repo, e.g., /project/.worktrees/feature/), this correctly returns the main repo root (/project/) by using git rev-parse --git-common-dir which always points to the main repo's .git directory. (GH#509) The result is cached after the first call.

func GetRepoRoot

func GetRepoRoot() string

GetRepoRoot returns the root directory of the current git repository. Returns empty string if not in a git repository.

This function is worktree-aware and handles Windows path normalization (Git on Windows may return paths like /c/Users/... or C:/Users/...). It also resolves symlinks to get the canonical path. The result is cached after the first call.

func IsWorktree

func IsWorktree() bool

IsWorktree returns true if the current directory is in a Git worktree. This is determined by comparing --git-dir and --git-common-dir. The result is cached after the first call since worktree status doesn't change during a single command execution.

func NormalizeBeadsRelPath

func NormalizeBeadsRelPath(relPath string) string

NormalizeBeadsRelPath strips any leading path components before .beads/. This handles bare repo worktrees where the relative path includes the worktree name (e.g., "main/.beads/issues.jsonl" -> ".beads/issues.jsonl"). GH#785, GH#810: Fix for sync failing across worktrees in bare repo setup.

func NormalizePath

func NormalizePath(path string) string

NormalizePath converts Git's Windows path formats to native format. Git on Windows may return paths like /c/Users/... or C:/Users/... This function converts them to native Windows format (C:\Users\...). On non-Windows systems, this is a no-op.

func ResetCaches

func ResetCaches()

ResetCaches resets all cached git information. This is intended for use by tests that need to change directory between subtests. In production, these caches are safe because the working directory doesn't change during a single command execution.

WARNING: Not thread-safe. Only call from single-threaded test contexts.

Types

type SyncOptions

type SyncOptions struct {
	// ForceOverwrite bypasses the merge logic and always overwrites the worktree
	// JSONL with the local JSONL. This should be set to true when the daemon
	// knows that a mutation (especially delete) occurred, so the local state
	// is authoritative and should not be merged with potentially stale worktree data.
	ForceOverwrite bool
}

SyncOptions configures the behavior of SyncJSONLToWorktree

type WorktreeManager

type WorktreeManager struct {
	// contains filtered or unexported fields
}

WorktreeManager handles git worktree lifecycle for separate beads branches

func NewWorktreeManager

func NewWorktreeManager(repoPath string) *WorktreeManager

NewWorktreeManager creates a new worktree manager for the given repository

func (*WorktreeManager) CheckWorktreeHealth

func (wm *WorktreeManager) CheckWorktreeHealth(worktreePath string) error

CheckWorktreeHealth verifies the worktree is in a good state and attempts to repair if needed

func (*WorktreeManager) CreateBeadsWorktree

func (wm *WorktreeManager) CreateBeadsWorktree(branch, worktreePath string) error

CreateBeadsWorktree creates a git worktree for the beads branch with sparse checkout Returns the path to the created worktree

func (*WorktreeManager) RemoveBeadsWorktree

func (wm *WorktreeManager) RemoveBeadsWorktree(worktreePath string) error

RemoveBeadsWorktree removes a git worktree and cleans up

func (*WorktreeManager) SyncJSONLToWorktree

func (wm *WorktreeManager) SyncJSONLToWorktree(worktreePath, jsonlRelPath string) error

SyncJSONLToWorktree syncs the JSONL file from main repo to worktree. If the worktree has issues that the local repo doesn't have, it merges them instead of overwriting. This prevents data loss when a fresh clone syncs with fewer issues than the remote. (bd-52q fix for GitHub #464) Note: This is a convenience wrapper that calls SyncJSONLToWorktreeWithOptions with default options (ForceOverwrite=false).

func (*WorktreeManager) SyncJSONLToWorktreeWithOptions

func (wm *WorktreeManager) SyncJSONLToWorktreeWithOptions(worktreePath, jsonlRelPath string, opts SyncOptions) error

SyncJSONLToWorktreeWithOptions syncs the JSONL file from main repo to worktree with configurable options. If ForceOverwrite is true, the local JSONL is always copied to the worktree, bypassing the merge logic. This is used when the daemon knows a mutation (especially delete) occurred and the local state is authoritative. If ForceOverwrite is false (default), the function uses merge logic to prevent data loss when a fresh clone syncs with fewer issues than the remote.

Jump to

Keyboard shortcuts

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