Skip to main content

Module worktree

Module worktree 

Source
Expand description

Linked worktree registry: discovery, listing, and admin-dir layout.

Git stores linked worktrees under <common-git-dir>/worktrees/<id>/ with gitdir, commondir, HEAD, and optional locked / prunable files. This module reads that layout; lifecycle mutations (add / remove) remain in the CLI for now and will move here in Phase 1.2.

Structs§

WorktreeEntry
One row returned by list_worktrees.

Functions§

allocate_worktree_admin_dir
Pick a unique <common>/worktrees/<id>/ directory for a new linked worktree at wt_path.
common_git_dir
Shared git directory for git_dir (follows commondir for linked worktrees).
copy_filtered_worktree_config
Copy config.worktree into a linked worktree admin dir, stripping keys Git omits when extensions.worktreeConfig is enabled (core.bare, core.worktree).
is_bare_repository
Whether common is configured as a bare repository (core.bare=true).
list_worktrees
Enumerate the main and linked worktrees for repo.
read_worktree_path
Read the working tree path from <admin>/gitdir (parent of the worktree .git file).
registered_worktree_count
Number of registered worktrees (main + linked entries under worktrees/).
resolve_linked_head
Resolve HEAD for a linked worktree admin dir (HEAD local, branch refs in common).
sanitize_worktree_id_component
Sanitize a path basename for use as worktrees/<id>/ (Git sanitize_refname_component).
worktree_path_basename
Last path component of path, without trailing directory separators (Git worktree_basename).