@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
94 lines • 5.15 kB
TypeScript
import type { NOOPAccessor } from '../../../../accessor/base.ts';
import { type PathSpec } from '../../../../types.ts';
import type { CommandFnResult, Context } from '../../../config.ts';
import type { Repo } from './repo.ts';
import type { TreeEntry } from './tree.ts';
import type { IndexEntry, RepoLocation, WorkTree } from './types.ts';
import type { Files } from '../../../../workspace/files.ts';
/** The parsed shape of a `git rm` invocation. */
export interface RmFlags {
/** `-r`, allow a directory operand. */
readonly recursive: boolean;
/** `--cached`, unstage only and keep the file. */
readonly cached: boolean;
/** `-f`, remove even over uncommitted changes. */
readonly force: boolean;
/** `-q`, print no `rm` line per path. */
readonly quiet: boolean;
/** `--ignore-unmatch`, an operand naming nothing is not an error. */
readonly ignoreUnmatch: boolean;
}
/**
* Which tracked paths the operands remove, in index order.
*
* Every operand is checked before anything is removed, which is git's order
* too: a line with one bad operand removes nothing. A directory is refused
* without `-r` rather than expanded, and an operand that names nothing tracked
* is a fatal unless `--ignore-unmatch` says otherwise. An untracked file is
* "nothing tracked": git has nothing to remove it from.
*/
export declare function select(location: RepoLocation, start: string, operands: readonly string[], tracked: ReadonlySet<string>, flags: RmFlags): string[];
/**
* Which absent paths a link above them is only hiding.
*
* git lstats a tracked path to decide whether it still has local work to lose,
* and that lstat resolves every component above the file, so a symlink standing
* where a directory was does not hide the file: it points the check at whatever
* lies at the other end, which is some other file entirely and therefore a
* local change. The walk answers the opposite way on purpose, because git's own
* diff refuses to follow a leading link and reports the path deleted, which is
* why `git status` says `D` here and `git rm` still refuses. Nothing is
* compared: two files agreeing byte for byte are still two files, and git
* refuses that case too. Pinned against git 2.50.1.
*
* @param vfs the session's files
* @param worktree absolute virtual path of the working tree root
* @param paths the selected paths that hold an index entry
* @param missing what the walk said about each path
*/
export declare function shadowed(vfs: Files, worktree: PathSpec, paths: readonly string[], missing: ReadonlyMap<string, string>): Promise<Set<string>>;
/**
* Refuse a removal that would throw away uncommitted work.
*
* git's own three-way test per path: whether the index differs from HEAD, and
* whether the working tree differs from the index. A path that differs both
* ways is refused outright; one that differs one way is refused unless
* `--cached` keeps the file. A file already gone from the working tree has no
* local change to lose, which is what makes `git rm <deleted>` the way to stage
* a deletion. Pinned against git 2.50.1.
*/
export declare function refuseLostWork(repo: Repo, vfs: Files, tree: ReadonlyMap<string, TreeEntry>, entries: ReadonlyMap<string, IndexEntry>, found: WorkTree, paths: readonly string[], cached: boolean): Promise<void>;
/**
* Delete every selected path from the working tree.
*
* A directory standing where a tracked file was is the one deletion a mount
* cannot make: `unlink` is not the call that empties a tree, and git reports
* the strerror rather than removing what it never tracked. It reports it in
* index order and only while nothing has been deleted yet; once one path is
* gone the rest of the loop tolerates a failure and the line still succeeds.
* That is git's own rule rather than a reading of it, and it is observable both
* ways: `git rm slot z.txt` is fatal with the index untouched, while
* `git rm a.txt slot` exits 0 with both entries unstaged and the directory
* still on disk. Pinned against git 2.50.1.
*
* A tracked symlink to a directory is not this case and must not be read as
* one: it is removed as the link it is, which is why the namespace is asked
* before the type.
*
* @param vfs the session's files
* @param worktree absolute virtual path of the working tree root
* @param selected the paths to delete, in index order
* @param lines the `rm` lines already printed, for a refusal to carry on stdout
* the way git prints them anyway
*/
export declare function clearWorktree(vfs: Files, worktree: PathSpec, selected: readonly string[], lines: string): Promise<void>;
/**
* Remove paths from the index, and from the working tree too.
*
* `--cached` leaves the file where it is and only stops tracking it. Without
* `-f` a path carrying uncommitted work is refused rather than deleted, which is
* the one check that makes the verb safe to hand an agent: there is no reflog
* here to recover a file from.
*/
export declare function rm(_accessor: NOOPAccessor, paths: PathSpec[], texts: string[], ctx: Context): Promise<CommandFnResult>;
//# sourceMappingURL=rm.d.ts.map