relpath

package
v0.93.0-rc.5 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package relpath validates the repo-relative paths lich receives from the page — a file picked in the review panel, a path parsed out of git's diff output — before they are joined onto a work-tree root. It is the one copy of that rule: every surface that opens, reads or deletes a file by relative path answers to it, so an escape closed here is closed everywhere.

Two rules, because the callers do not all want the same one. Validate is the lexical rule and answers for the path as written — what a caller passing rel to git or unlinking it needs. Resolve adds the filesystem: it follows the links and proves the result is still in the tree, which only a caller that reads the file's bytes has to care about.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Escapes

func Escapes(rel string) bool

Escapes reports whether a relative path names the parent or anything below it. Callers use filepath.Rel first when they begin with absolute paths.

func Resolve

func Resolve(root, rel string) (string, error)

Resolve validates rel, joins it onto root and returns the real path to open: every symlink resolved, and proven to still be inside root. Validate alone answers the path as written, which is the whole rule for a caller that hands rel to git or unlinks it — but not for one that reads bytes, because a checkout may ship a link and following it lands wherever the link points.

git stores such an entry as its target text, so the diff beside a preview says `../../etc/hosts` while the preview would print that file. Refusing here is what keeps the two telling the same story about the same tree.

Both sides are resolved before they are compared: a checkout is routinely reached through a link itself (macOS `/var` is `/private/var`), and measuring a resolved target against an unresolved root calls every file an escape.

func Validate

func Validate(rel string) error

Validate rejects rooted paths, parent-directory escapes and the work-tree root itself, so joining rel onto a work-tree root can never leave it — and can never name the whole tree. The root is refused because a caller that means one file is handed every file instead: `git rm -f --cached -- .` empties the index (see project.DiscardFile). It is also what an empty path cleans to, so a missing argument stops here rather than at the git call.

Types

This section is empty.

Jump to

Keyboard shortcuts

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