Skip to main content

Module repo

Module repo 

Source
Expand description

Repo mode: one checkout, cleaned the way git clean -fdx cleans it.

This is the port of the unpublished Node @agentender/pristine, and the whole of its good idea is that it enumerates nothing itself. Point it at a work tree and it asks git what it would remove, then removes that. What comes free is every part of gitignore that a hand-rolled matcher gets subtly wrong: nested .gitignore files, negations, info/exclude, the user’s global excludes, and the refusal to descend into a nested repository.

§Why git clean -n and not git ls-files --directory

The original design enumerated with git ls-files --others --directory, and dogfooding it cost real data. --directory collapses a directory to dir/ based only on the absence of tracked files, so .nx/ — an ignored cache beside untracked data, with nothing tracked in it — collapsed to one entry .nx/. Removing untracked files then also wiped the ignored cache the user had chosen to keep.

git clean collapses a directory only when everything inside it is being removed, and descends otherwise. Measured on that exact shape: git clean -n -d prints .nx/workspace-data/ and git clean -n -d -X prints .nx/cache/. The two lists are disjoint by construction, which is why both can be offered as independent choices.

§Reading git’s prose, which is the one uncomfortable part

git clean has no -z and no porcelain format. It prints Would remove <path> and Would skip repository <path>, so this module parses sentences, and two things follow.

The sentences are translated, which [crate::git::git] handles by forcing the C locale for every invocation. And the paths are quoted — git’s own C-style escaping — which [unquote] undoes. A line matching neither sentence is an error, never a target and never silence: not understanding git’s output is exactly the state in which nothing may be deleted.

Structs§

Concealed
An entry left where it is because of what is under it rather than what it is.
Enumeration
What git says it would remove from one work tree.
Repo
One git work tree, asked what it would clean.
Selected
The targets a Selection picks out of an Enumeration, and what it left behind.
Selection
What a run was asked to do, however it was asked.

Enums§

Class
Which of the three classes an entry falls in.
Conceals
What a directory holds that the run was not asked to remove.
RepoError
Why a work tree could not be cleaned.
Reset
What to do about tracked files that have been changed.

Functions§

classify
Which class entry falls in, judged only from its path, which must be relative to the work tree root.
select
Applies a selection to an enumeration.