Repository navigation
feat: find the config by searching up to the top of the work tree - #250
Merged
Merged
Conversation
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
marked this pull request as ready for review
November 2, 2026 16:04
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 |
6 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.tomlscanned that subdirectory alone,initwrote a config there, andinit --config-path lint/my.tomlwrote a file thatchecknever looked at. A.agents/deslag.tomlbeside a.deslag/config.tomlof another schema leftcheckexiting 0 with every lint off.What changed:
.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..agents/deslag.tomlgives the parent of.agents/. A config below the top of the work tree roots a run at or below it.allowpaths,--diffand--base, the text report, JSON, SARIF and GitHub annotations, and the pathsfixandexplaintake. A path copied from a report works anywhere. When the root is not the current directory,check,fixandexplainprint 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.deslag init.initrefuses where the search finds a config. With no--config-pathit writesdeslag.tomlat the top of the work tree. A--config-pathmust end in a canonical TOML location whose root is the current directory or an ancestor within the work tree, else exit 2 listing them.initcreates the one parent directory a stem needs. Socheckfrom the same directory reads whatinitwrote, with no flag.updateandinstructions updateuse the same search, so they edit the configcheckreads. Without it,instructions updatefrom a subdirectory said no config was found in a work tree that has one.pathdoc comment, which reachesdeslag 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, andGIT_CEILING_DIRECTORIES.Decided on the maintainer's behalf
.gitand never search to/..config/deslagis a canonical stem, so a search to/would take~/.config/deslag.tomland walk the home directory. The probe is a file test, not git, socheckneeds no git without--base..gitends the search, so a run inside it does not find the config of the repository around it. This follows from the first decision.--config-pathis 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..agents/config and a.deslag/one is howcheckcame to exit 0 with every lint off.initaccepts only a pathcheckwould look at. Other commands still take any--config-path.updateandinstructions updatefollow 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,.gitas a file, nearer and farther configs, two stems, no work tree, an explicit path) andtests/root.rs(check,--config-path, anallowentry,explainandfix, a config below the top, nothing read above the top,.gitas a file, no work tree, two stems,updatefrom a subdirectory,initfrom a subdirectory,init --config-pathand its refusals, and the note line for a config outside the work tree).tests/slow/diff.rsruns--diffand--basefrom a subdirectory.Changed, each read:
an_earlier_location_in_any_language_winsintests/formats.rsis now a refusal naming both files; theinit --config-pathtest intests/slow/init.rsnow refuseslint.tomland accepts.agents/deslag.toml; the subdirectory test intests/instructions.rsnow finds the config from a subdirectory; the missing-config test intests/unit.rsexpectsdeslag initin 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-winsand the testthe_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:
/: three search unit tests and three integration tests.gita directory only: the search unit test for a.gitfile anda_git_file_ends_the_search_as_a_directory_doesa_config_below_the_top_roots_a_run_at_or_below_it--config-pathrooted at the current directory: the explicit-path unit test andconfig_path_from_a_subdirectory_scans_the_repo_from_its_topinitmakes no parent directory:init_config_path_makes_its_parent_and_check_finds_the_fileand the slowinittestupdatereading the current directory:update_from_a_subdirectory_edits_the_config_at_the_rootsrc/instructions/guide.mdis 4,730 bytes of its 4,847.Testing
make ci-fast: exit 0make test: exit 0make test-tools: exit 0References