Skip to content

feat: warn about unknown fields in config files at load time - #758

Merged
max-sixty merged 2 commits into
mainfrom
config-missing
Jan 20, 2026
Merged

max-sixty merged 2 commits into
mainfrom
config-missing

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Summary

  • Add warnings for unknown fields in config files at load time
  • Previously, unknown fields (typos like [commit-gen] instead of [commit-generation]) were only shown via wt config show
  • Now warnings appear immediately when config is loaded, helping users discover issues faster

Changes

  • Add warn_unknown_fields() function with per-process deduplication (same pattern as deprecation warnings)
  • Call from UserConfig::load() and ProjectConfig::load()
  • Check file content directly to avoid false positives from env vars
  • Only warn in main worktree for project config (where file is editable)

Example output

▲ User config has unknown field: commit-gen (will be ignored)
▲ Project config has unknown fields: post-merge-command, pre-commit-hook (will be ignored)

Test plan

  • All existing tests pass (895 tests)
  • Fixed test configs that incorrectly used worktree-path in project configs

🤖 Generated with Claude Code

max-sixty and others added 2 commits January 19, 2026 23:20
Previously, unknown fields in config files (typos like `[commit-gen]`
instead of `[commit-generation]`) were only shown via `wt config show`.
Now warnings appear at config load time, helping users discover issues
immediately.

- Add `warn_unknown_fields()` function with per-process deduplication
- Call from `UserConfig::load()` and `ProjectConfig::load()`
- Check file content directly to avoid false positives from env vars
- Only warn in main worktree for project config (where file is editable)

Also fixes test configs that incorrectly used `worktree-path` in project
configs (it's a user config field).

Co-Authored-By: Claude <[email protected]>
Resolve conflict in deprecation.rs by adopting LazyLock pattern from main
for both WARNED_DEPRECATED_PATHS and WARNED_UNKNOWN_PATHS statics.

Co-Authored-By: Claude <[email protected]>
@max-sixty
max-sixty merged commit da73464 into main Jan 20, 2026
@max-sixty
max-sixty deleted the config-missing branch January 20, 2026 07:40
max-sixty pushed a commit that referenced this pull request Sep 16, 2026
…4145)

## Problem

`ProjectConfig::load` gated its unknown-field warning on
`is_main_worktree`, so
the "key … will be ignored" message never fired outside the primary
worktree.
`wt merge` runs from the feature worktree, which is why the issue reads
as a
`wt merge` gap — but the suppression is the load path, not the command.
`wt
list`, `wt switch`, and every other command are equally silent there:

```
$ cd repo.feat && wt list         # .config/wt.toml has [merge]
(nothing)
$ cd repo && wt list
▲ Project config has unknown field … (will be ignored)
```

`wt config show` warns from anywhere because it renders the same
warnings
through its own path (`collect_unknown_warnings`), which has no such
gate. A
bare repo, where every worktree is linked, never saw the warning at all.

The consequence the issue describes follows from that: a project
`[merge]`
section is dropped at runtime with nothing said, so a machine carrying
the
`[projects."<id>"]` entry in user config merges one way and a fresh
checkout of
the same repo merges the other.

## Solution

Drop the gate. The warning's fix — edit the tracked `.config/wt.toml`,
or move
the key into user config — is available from any worktree, so "only in
main
worktree where it's actionable" (#758) doesn't hold for this channel.

The adjacent deprecation channel keeps its gate. That one's message
points at
`wt config update`, which does need the primary worktree, and
`format_deprecation_details` already has separate linked-worktree
handling for
it. Emission stays deduped per path per process and still respects
`suppress_warnings()`, so the picker and `wt list statusline` are
unaffected.

## Testing

`test_misplaced_project_key_warns_from_linked_worktree` writes `[merge]`
into a
linked worktree's project config and asserts the warning on `wt list`
there. It
fails on `main` ("got: ○ Showing 5 worktrees…") and passes with the
change. It
sits beside `test_unknown_project_key_warning_during_load`, its
primary-worktree
counterpart.

The issue's own repro now warns before merging:

```
$ wt -C ../repro.feat merge --no-remove
▲ Project config has key merge which belongs in user config (will be ignored); to scope it to this repo, add it under [projects."<id>"] in user config
◎ Merging 1 commit to main @ 1552839 …
```

`cargo test --test integration` is green (2181 passed) apart from two
`step_copy_ignored` cases that also fail on an unmodified tree in this
sandbox
— `AF_UNIX` bind is blocked and the umask is 0002. Same for

`copy::tests::test_copy_dir_recursive_does_not_count_a_non_regular_file`
under
`--lib`. `cargo fmt --check` and `cargo clippy --all-targets` are clean.

Closes #4144 — automated triage

Co-authored-by: worktrunk-bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant