Documentation
¶
Overview ¶
Package worktreedir owns access to the files of the working tree itself.
It is the third of Entire's three anchors, alongside entiredir (.entire) and gitdir (the git common dir), and the loosest of them: a root here contains operations to the repository rather than to a directory Entire owns. That is still worth having, because the paths that reach these reads and writes are not Entire's own:
- Checkpoint writes read working files named by `git status` output, on the hook path, to turn them into blobs.
- Rewind writes working files named by git TREE ENTRIES out of a checkpoint, which may have been fetched from a remote. Its restore half already opened a root for exactly this reason; the reads beside it did not.
- Diff-stat and gather read working files named from status output too.
A root makes "cannot leave the repository" a property of the handle rather than of each caller remembering to validate. It is not a substitute for the tree-path validation those callers do — normalizeRepoRelativeTreePath still rejects names that are not repo-relative before they are used as git paths — it is the layer underneath it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Name ¶
Name converts a path inside the worktree to a name relative to its root, accepting either an absolute path or one already relative to the root.
Git hands out slash-separated repo-relative paths and Entire assembles absolute ones from them; this is the single conversion back, so callers stop joining a root path onto a git path and reading the result.
func NameFollowingLinks ¶ added in v0.10.6
NameFollowingLinks is Name for a path that may itself be, or sit below, a symlink: it resolves the link first and then answers for the target.
os.Root refuses an ABSOLUTE symlink target unconditionally, including one resolving inside the root, so a root alone cannot express "follow a link that stays in the worktree, refuse one that leaves". That distinction is what a user-owned working-tree file needs — pointing vercel.json at a monorepo's shared config is a real setup, and it is written absolute as often as relative — while Entire's own trees (.entire, an agent's hook config) refuse a link either way and must not use this.
The name returned is worktree-relative and symlink-free, so the caller's read still goes through the root: a link repointed between the resolve and the read changes which in-worktree file is read and cannot escape the worktree.
A dangling link reports os.ErrNotExist, matching what os.Stat gives for one.
Types ¶
This section is empty.