Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

fix(config): report ignored project-config keys from every worktree (#4145)

Worktrunk Botbe39a71eb2bb
diff --git a/src/config/project.rs b/src/config/project.rs
index 833fe886a..ad3fcb26a 100644
--- a/src/config/project.rs
+++ b/src/config/project.rs
@@ -293,16 +293,22 @@ impl ProjectConfig {
.map_err(|e| ConfigError(e.to_string()))?
.migrated_content;
- // Warn about unknown fields (only in main worktree where it's actionable).
+ // Warn about unknown fields, from every worktree. Unlike the
+ // deprecation channel above — whose message points at `wt config
+ // update`, which needs the primary worktree — this one just reports
+ // that a key is being ignored, and its fix (edit the tracked file, or
+ // move the key to user config) is available from any worktree. Gating
+ // it on the primary hid it from the commands the keys govern: `wt
+ // merge` runs from the feature worktree, so a project `[merge]`
+ // section was silently dropped with nothing said (#4144).
+ //
// Runs on the raw contents so deprecated keys are detected as written;
// `DEPRECATED_SECTION_KEYS` defers them to the deprecation messaging.
- if is_main_worktree {
- super::deprecation::warn_unknown_fields::<ProjectConfig>(
- &contents,
- &config_path,
- super::ConfigFileKind::Project,
- );
- }
+ super::deprecation::warn_unknown_fields::<ProjectConfig>(
+ &contents,
+ &config_path,
+ super::ConfigFileKind::Project,
+ );
// Deserialize the structurally migrated content so deprecated keys
// (e.g. `pre-start`/`post-start`) still load into their canonical fields.
diff --git a/tests/integration_tests/config_show.rs b/tests/integration_tests/config_show.rs
index 6ec421cbf..c539d6f17 100644
--- a/tests/integration_tests/config_show.rs
+++ b/tests/integration_tests/config_show.rs
@@ -1324,6 +1324,43 @@ fn test_unknown_project_key_warning_during_load(repo: TestRepo, temp_home: TempD
);
}
+/// The load-time unknown-field warning fires from a linked worktree too.
+///
+/// `[merge]` in project config is ignored at runtime, and the warning is the
+/// only thing that says so. Suppressing it outside the primary worktree hid it
+/// from exactly the commands the keys govern — `wt merge` runs from the
+/// feature worktree — so a repo's merge policy diverged silently between a
+/// machine carrying the `[projects."<id>"]` entry and a fresh checkout (#4144).
+#[rstest]
+fn test_misplaced_project_key_warns_from_linked_worktree(mut repo: TestRepo, temp_home: TempDir) {
+ let feature_wt = repo.add_worktree("feature");
+
+ // `[merge]` is user-config-only, so project config ignores it entirely.
+ let config_dir = feature_wt.join(".config");
+ fs::create_dir_all(&config_dir).unwrap();
+ fs::write(
+ config_dir.join("wt.toml"),
+ "[merge]\nsquash = false\nff = false\n",
+ )
+ .unwrap();
+
+ let mut cmd = repo.wt_command();
+ cmd.arg("list").current_dir(&feature_wt);
+ set_temp_home_env(&mut cmd, temp_home.path());
+
+ let output = cmd.output().unwrap();
+ assert!(
+ output.status.success(),
+ "Command should succeed: {}",
+ String::from_utf8_lossy(&output.stderr)
+ );
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ assert!(
+ stderr.contains("belongs in user config"),
+ "Expected misplaced-key warning from a linked worktree, got: {stderr}"
+ );
+}
+
/// Tests that when a user-config-only key (commit-generation) appears in project config,
/// the warning suggests moving it to user config.
#[rstest]