@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
99 lines • 4.88 kB
TypeScript
import type { RepoLocation } from './types.ts';
/**
* The virtual path a path operand names.
*
* Resolved against the directory git was told to run in, not the session's,
* because `-C` moves before anything else happens and a pathspec is read from
* where git ended up. Resolving against the session cwd instead would make
* `git -C /repo add letters.txt` reach for a file beside the shell rather than
* inside the repository.
*
* @param start absolute virtual path git is running in
* @param operand the operand as the user spelled it
*/
export declare function absoluteOperand(start: string, operand: string): string;
/**
* A path operand as a repository-relative path.
*
* Empty string for the working tree root itself, which is what `git add .` from
* the top resolves to and means "everything". Git uses the work tree as the
* base when invoked from outside it, as with --git-dir and --work-tree.
*
* @param location the discovered repository
* @param start absolute virtual path git is running in
* @param operand the operand as the user spelled it
*/
export declare function repoRelative(location: RepoLocation, start: string, operand: string): string;
/**
* Whether a repository-relative path sits inside a directory. An empty
* directory is the working tree root, which everything is under.
*
* @param path repository-relative path
* @param directory repository-relative directory
*/
export declare function under(path: string, directory: string): boolean;
/**
* Every path a single operand selects: itself and its whole subtree.
*
* Both, not one or the other. A pathspec matches a path that equals it
* and a path it is a leading directory of, and the two are not exclusive
* as soon as the candidates come from more than one tree: restoring
* `slot` where the index holds the file `slot` and the source holds
* `slot/child` has to select both, or the file is deleted and the
* directory never written. git 2.50.1 replaces one with the other in
* either direction.
*
* @param paths the candidate paths, repository-relative
* @param target the operand, repository-relative
*/
export declare function matched(paths: Iterable<string>, target: string): Set<string>;
/**
* Pathspec operands as the repository-relative patterns they name.
*
* A trailing slash survives, because `docs/` names only what lies under a
* directory where `docs` also names a file of that name. An empty operand is
* git's own refusal, and magic (`:(top)`, `:!`) is refused as unsupported
* rather than matched as a path.
*
* @param location the discovered repository
* @param start absolute virtual path git is running in
* @param operands the pathspecs as typed
*/
export declare function pathspecPatterns(location: RepoLocation, start: string, operands: readonly string[]): string[];
/**
* Whether a repository-relative path is one a pathspec names.
*
* git's default pathspec: a path it spells, a directory the path lies under
* (`docs` and `docs/` both name `docs/a.md`, only `docs` names a file `docs`),
* or a wildcard pattern matching the whole path. A wildcard crosses `/`, so
* `*.c` finds `sub/x.c`, and matches bytes, so `??.txt` is what names `é.txt`
* (pinned against git 2.54). A tree a diff does not descend into is also named
* by a pathspec inside it, which is how `diff-tree A -- dir/x` prints `dir`.
*
* @param path repository-relative path, surrogate-escaped
* @param patterns patterns from `pathspecPatterns`
* @param directory whether the path is a tree left undescended
*/
export declare function pathspecSelects(path: string, patterns: readonly string[], directory?: boolean): boolean;
/**
* Where a walk has to go to see every path some patterns name: each
* pattern's leading literal part, the path it spells or the directory above
* its first wildcard. Null when one of them names the whole tree (`.`,
* `*.c`), or when there are none. `literal` says the operands are paths, as
* `git add` and `git rm` take them, so a wildcard is part of a name. Mirrors
* Python's `pattern_roots`.
*/
export declare function patternRoots(patterns: Iterable<string>, literal?: boolean): string[] | null;
/**
* Whether a repository entry belongs to the session's visible tree.
*
* For what git does to the index, never what it prints: a verb that
* stages, removes or resets acts only on the entries the session sees, and
* a hidden tracked file (absent from a worktree scan) is not taken for a
* deletion. What git prints it hands over as rows, which the command
* boundary filters.
*/
export declare function visiblePath(location: RepoLocation, relative: string): boolean;
/** A session view of Git entries; the persistent mapping stays intact. */
export declare function visibleEntries<T>(location: RepoLocation, entries: ReadonlyMap<string, T>): Map<string, T>;
//# sourceMappingURL=pathspec.d.ts.map