Skip to content

feat: find the config by searching up to the top of the work tree - #250

Merged
webern merged 8 commits into
m/deslag-guideroomfrom
m/deslag-root
Nov 2, 2026
Merged

webern merged 8 commits into
m/deslag-guideroomfrom
m/deslag-root

Conversation

@webern

@webern webern commented Nov 2, 2026

Copy link
Copy Markdown
Owner

This builds on #247 and shows only its own diff until #247 merges.

AI Summary

deslag used to take the directory it ran in as the root of the repository. Run from a subdirectory, check --config-path ../deslag.toml scanned that subdirectory alone, init wrote a config there, and init --config-path lint/my.toml wrote a file that check never looked at. A .agents/deslag.toml beside a .deslag/config.toml of another schema left check exiting 0 with every lint off.

What changed:

  • The config is found by searching from the current directory up to the nearest directory that holds a .git, a file or a directory, and no further. Outside a work tree only the current directory is searched. The first directory with a config at a canonical location is the root.
  • The root is the directory the config path is relative to: .agents/deslag.toml gives the parent of .agents/. A config below the top of the work tree roots a run at or below it.
  • Findings and paths are relative to the root from any directory: globs, allow paths, --diff and --base, the text report, JSON, SARIF and GitHub annotations, and the paths fix and explain take. A path copied from a report works anywhere. When the root is not the current directory, check, fix and explain print one stderr line naming the root and the config. The config is shown from the root where it is under the root, and absolute otherwise.
  • No config exits 2 and names the directories searched, the paths tried and deslag init.
  • Two configs in one directory, at any canonical locations and in any language, exit 2 naming each.
  • init refuses where the search finds a config. With no --config-path it writes deslag.toml at the top of the work tree. A --config-path must end in a canonical TOML location whose root is the current directory or an ancestor within the work tree, else exit 2 listing them. init creates the one parent directory a stem needs. So check from the same directory reads what init wrote, with no flag.
  • update and instructions update use the same search, so they edit the config check reads. Without it, instructions update from a subdirectory said no config was found in a work tree that has one.
  • The guide, the README, the help text and the code docs say this. The JSON path doc comment, which reaches deslag instructions output-schema, now says the path is relative to the config's directory.

Out of scope: a global config (#63), a smarter init, ignore files above a root below the top of the work tree, and GIT_CEILING_DIRECTORIES.

Decided on the maintainer's behalf

  • Stop at the nearest .git and never search to /. .config/deslag is a canonical stem, so a search to / would take ~/.config/deslag.toml and walk the home directory. The probe is a file test, not git, so check needs no git without --base.
  • The nearer config wins over a farther one, silently. Nothing above the first directory with a config is read and nothing is merged, as Ideas from Vale that deslag is not taking #34 asks. The alternative, refusing or merging, would read two files.
  • A submodule or nested repository hides the parent's config. Its .git ends the search, so a run inside it does not find the config of the repository around it. This follows from the first decision.
  • --config-path is rooted at the top of the work tree, or at the current directory outside one, so the same flag gives the same report from any directory.
  • Two configs in one directory are refused, not ordered. A silent pick between a .agents/ config and a .deslag/ one is how check came to exit 0 with every lint off.
  • init accepts only a path check would look at. Other commands still take any --config-path.
  • update and instructions update follow the search, as above.

Tests

New, in the fast tier: unit tests for the search in src/config/search.rs (config at the current directory, two levels up, above .git, .git as a file, nearer and farther configs, two stems, no work tree, an explicit path) and tests/root.rs (check, --config-path, an allow entry, explain and fix, a config below the top, nothing read above the top, .git as a file, no work tree, two stems, update from a subdirectory, init from a subdirectory, init --config-path and its refusals, and the note line for a config outside the work tree). tests/slow/diff.rs runs --diff and --base from a subdirectory.

Changed, each read: an_earlier_location_in_any_language_wins in tests/formats.rs is now a refusal naming both files; the init --config-path test in tests/slow/init.rs now refuses lint.toml and accepts .agents/deslag.toml; the subdirectory test in tests/instructions.rs now finds the config from a subdirectory; the missing-config test in tests/unit.rs expects deslag init in place of "are you in the root". Two assertions moved from "at one location" to "in one directory" with the new message.

Deleted: the corpus case the-earlier-canonical-location-wins and the test the_earlier_canonical_location_wins. Both asserted the opposite of the new rule, that the first of two configs wins. The case was a test config over fixtures; no fixture or golden changed. No golden, case or corpus output moved, because every one of them runs at its root.

Mutations, each failing at least one test with the change in place:

  • search to /: three search unit tests and three integration tests
  • .git a directory only: the search unit test for a .git file and a_git_file_ends_the_search_as_a_directory_does
  • farthest config wins: the nearest-wins unit test and a_config_below_the_top_roots_a_run_at_or_below_it
  • first stem wins: one search unit test and four integration tests
  • --config-path rooted at the current directory: the explicit-path unit test and config_path_from_a_subdirectory_scans_the_repo_from_its_top
  • init makes no parent directory: init_config_path_makes_its_parent_and_check_finds_the_file and the slow init test
  • update reading the current directory: update_from_a_subdirectory_edits_the_config_at_the_root

src/instructions/guide.md is 4,730 bytes of its 4,847.

Testing

  • make ci-fast: exit 0
  • make test: exit 0
  • make test-tools: exit 0

References

Every command took the current directory as the repo root, so a run
from a subdirectory scanned that subdirectory alone and did not find
the config at all.

The root is now the nearest directory, from where deslag runs up to the
top of the git work tree, that holds a config at a canonical location.
The top is the nearest directory with a .git entry, file or directory.
Outside a work tree only the current directory is looked in. The search
is bounded because .config/deslag is a canonical stem, and a search to
/ would take ~/.config/deslag.toml and walk the home directory.

Globs, allow paths, --diff, --base, the reports, and the paths given to
fix and explain stay relative to the root, so a path copied from a
report works from anywhere. When the root is not the current directory,
check, fix and explain print one line naming the root and the config.
--config-path roots the run at the top of the work tree.

Configs at two canonical locations in one directory are now an error,
as two languages at one stem already were. Before, the earlier stem won
silently and a config at a later one was ignored.
init took any --config-path, so lint/my.toml was written where check
could not see it, .deslag/config.toml failed for want of a parent, and
../x.toml landed outside the repo. With no --config-path it wrote
deslag.toml in the current directory, which from a subdirectory is not
where check looks.

Now init refuses wherever the config search finds a config. With no
--config-path it writes deslag.toml at the top of the git work tree, or
in the current directory outside one. A --config-path must end with a
canonical TOML location whose root is the current directory or a
directory above it within the work tree, else init exits 2 and lists
them. It makes the one parent directory a stem such as .agents needs.
Check run from the same directory then reads what init wrote, with no
flag.
The error for two configs now says they are in one directory, since two
canonical locations count and not only two languages at one. Drop the
unit test that expected the earlier location to win, which the
formats test now covers as a refusal.
The setup guide, the README, the help for the path arguments and the
update topic said deslag runs from the repository root. It now finds the
config at or above where it runs, up to the top of the git work tree,
and every path is relative to the directory that holds it.
The comment still said the repo root, where deslag ran. The root is the
directory of the config now, and the path is the same from any directory
deslag runs in. The comment is part of the output schema text.
With --config-path the note printed the path as given, relative to the
directory deslag ran in, next to a root that is somewhere else. Now the
note shows the config from the root when it is under the root, and
absolute when it is not.
deslag update uses the same search as check, but no test ran it from a
subdirectory; reverting it to the current directory failed nothing. A
.git file, as in a linked worktree or a submodule, ended the search
only in a unit test; the new test runs the binary with a config above
the file.
@webern webern added enhancement New feature or request ai Primarily authored by AI (whether PR, Issue, Whatever) area/config Has to do with deslag configuration (deslag.yaml, etc.) area/cli Deals with the command line interface. labels Nov 2, 2026
@webern
webern marked this pull request as ready for review November 2, 2026 16:04
@webern

webern commented Nov 2, 2026

Copy link
Copy Markdown
Owner Author

CI is green on ca5a97b (run 41477137567).

Decided on the maintainer's behalf: the search for the config stops at the top of the work tree, the nearest .git file or directory above the current directory, and never continues toward /. A config above the work tree, or in a parent repo above a nested one, is not found, and the report says which directories were searched and how to run deslag init. The alternative, searching to the filesystem root, would let a config outside the repository change what CI checks.

@webern webern added the approved The PR is approved for merging. label Nov 2, 2026
@webern
webern added this pull request to stack #256 November 2, 2026 16:34
@webern
webern merged commit eff611d into main Nov 2, 2026
6 checks passed
@webern
webern deleted the m/deslag-root branch November 2, 2026 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai Primarily authored by AI (whether PR, Issue, Whatever) approved The PR is approved for merging. area/cli Deals with the command line interface. area/config Has to do with deslag configuration (deslag.yaml, etc.) enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant