Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix: use gutter for config update hint and add -C for linked worktrees (#1137)
Maximilian Roos882d4e77c582
diff --git a/src/commands/config/update.rs b/src/commands/config/update.rsindex c4be9c4a0..84e35ec18 100644--- a/src/commands/config/update.rs+++ b/src/commands/config/update.rs@@ -10,7 +10,9 @@ use worktrunk::config::{DeprecationInfo, format_deprecation_warnings, format_migration_diff, get_config_path,};use worktrunk::git::Repository;-use worktrunk::styling::{eprintln, info_message, success_message};+use worktrunk::styling::{+ eprintln, format_bash_with_gutter, hint_message, info_message, success_message,+};use crate::output::prompt::{PromptResponse, prompt_yes_no_preview};@@ -152,22 +154,14 @@ fn check_project_config() -> anyhow::Result<Option<UpdateCandidate>> {return Ok(None);}- // Only update from main worktree (linked worktrees share the config)let is_linked = repo.current_worktree().is_linked().unwrap_or(true);- if is_linked {- eprintln!(- "{}",- info_message("Project config update must run from main worktree")- );- return Ok(None);- }let content = std::fs::read_to_string(&config_path).context("Failed to read project config")?;let info = match worktrunk::config::check_and_migrate(&config_path,&content,- true, // warn_and_migrate+ !is_linked, // only write .new file from main worktree"Project config",Some(&repo),false, // silent mode@@ -176,6 +170,17 @@ fn check_project_config() -> anyhow::Result<Option<UpdateCandidate>> {_ => return Ok(None),};+ // Linked worktrees can't apply the update — suggest -C to main worktree+ if is_linked {+ let display_path = worktrunk::path::format_path_for_display(repo.repo_path());+ eprintln!("{}", hint_message("To update project config:"));+ eprintln!(+ "{}",+ format_bash_with_gutter(&format!("wt -C {display_path} config update"))+ );+ return Ok(None);+ }+let new_path = match &info.migration_path {Some(path) => path.clone(),None => anyhow::bail!("Failed to write migration file for project config"),diff --git a/src/config/deprecation.rs b/src/config/deprecation.rsindex a8e8bd9d4..3b66a0fb0 100644--- a/src/config/deprecation.rs+++ b/src/config/deprecation.rs@@ -29,7 +29,9 @@ use shell_escape::unix::escape;use crate::config::WorktrunkConfig;use crate::shell_exec::Cmd;-use crate::styling::{eprintln, format_with_gutter, hint_message, warning_message};+use crate::styling::{+ eprintln, format_bash_with_gutter, format_with_gutter, hint_message, warning_message,+};/// Tracks which config paths have already shown deprecation warnings this process./// Prevents repeated warnings when config is loaded multiple times.@@ -633,8 +635,8 @@ pub struct DeprecationInfo {pub deprecations: Deprecations,/// Label for this config (e.g., "User config", "Project config")pub label: String,- /// True if in a linked worktree (migration file written to main worktree only)- pub in_linked_worktree: bool,+ /// Main worktree path when viewing from a linked worktree (for `-C` in hints)+ pub main_worktree_path: Option<PathBuf>,/// Path to approvals.toml if approved-commands were copied there during migrationpub approvals_copied_to: Option<PathBuf>,}@@ -715,7 +717,11 @@ pub fn check_and_migrate(migration_path: None,deprecations,label: label.to_string(),- in_linked_worktree: !warn_and_migrate,+ main_worktree_path: if !warn_and_migrate {+ repo.map(|r| r.repo_path().to_path_buf())+ } else {+ None+ },approvals_copied_to: None,};@@ -965,24 +971,21 @@ pub fn format_deprecation_details(info: &DeprecationInfo) -> String {// Migration hint with apply commandif let Some(new_path) = &info.migration_path {- let _ = writeln!(- out,- "{}",- hint_message(cformat!("Run <bright-black>wt config update</> to apply"))- );+ let _ = writeln!(out, "{}", hint_message("To apply:"));+ let _ = writeln!(out, "{}", format_bash_with_gutter("wt config update"));// Inline diff — git diff header shows the file pathsif let Some(diff) = format_migration_diff(&info.config_path, new_path) {let _ = writeln!(out, "{diff}");}- } else if info.in_linked_worktree {- // In linked worktree - migration file is written to main worktree+ } else if let Some(main_path) = &info.main_worktree_path {+ // In linked worktree — include -C so the command works from here+ let display_path = crate::path::format_path_for_display(main_path);+ let _ = writeln!(out, "{}", hint_message("To apply:"));let _ = writeln!(out,"{}",- hint_message(cformat!(- "Run <bright-black>wt config update</> from main worktree to apply",- ))+ format_bash_with_gutter(&format!("wt -C {display_path} config update")));}@@ -2140,7 +2143,7 @@ approved-commands = ["npm install"]select: false,},label: "User config".to_string(),- in_linked_worktree: false,+ main_worktree_path: None,approvals_copied_to: None,};let output = format_deprecation_details(&info);@@ -2168,7 +2171,7 @@ approved-commands = ["npm install"]select: false,},label: "User config".to_string(),- in_linked_worktree: false,+ main_worktree_path: None,approvals_copied_to: Some(std::path::PathBuf::from("/tmp/approvals.toml")),};let output = format_deprecation_details(&info);@@ -2455,7 +2458,7 @@ branches = trueselect: true,},label: "User config".to_string(),- in_linked_worktree: false,+ main_worktree_path: None,approvals_copied_to: None,};let output = format_deprecation_details(&info);diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_always_regenerates_migration_file.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_always_regenerates_migration_file.snapindex 152b77c13..cf8eabb61 100644--- a/tests/snapshots/integration__integration_tests__config_show__config_show_always_regenerates_migration_file.snap+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_always_regenerates_migration_file.snap@@ -46,7 +46,8 @@ exit_code: 0[36mPROJECT CONFIG[39m _REPO_/.config/wt.toml[33m▲[39m [33mProject config uses deprecated template variables: [2mmain_worktree[22m → [1mrepo[22m[39m-[2m↳[22m [2mRun [90mwt config update[39m to apply[22m+[2m↳[22m [2mTo apply:[22m+[107m [0m [2m[0m[2m[34mwt[0m[2m config update[107m [0m [1mdiff --git a_REPO_/.config/wt.toml b_REPO_/.config/wt.toml.new[m[107m [0m [1mindex 8fcdb47..42cb136 100644[m[107m [0m [1m--- a_REPO_/.config/wt.toml[mdiff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_displays_deprecation_details.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_displays_deprecation_details.snapindex c78cd4dd9..063585167 100644--- a/tests/snapshots/integration__integration_tests__config_show__config_show_displays_deprecation_details.snap+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_displays_deprecation_details.snap@@ -43,7 +43,8 @@ exit_code: 0----- stderr -----[36mUSER CONFIG[39m ~/.config/worktrunk/config.toml[33m▲[39m [33mUser config uses deprecated template variables: [2mrepo_root[22m → [1mrepo_path[22m, [2mmain_worktree[22m → [1mrepo[22m[39m-[2m↳[22m [2mRun [90mwt config update[39m to apply[22m+[2m↳[22m [2mTo apply:[22m+[107m [0m [2m[0m[2m[34mwt[0m[2m config update[107m [0m [1mdiff --git a[TEMP_HOME]/.config/worktrunk/config.toml b[TEMP_HOME]/.config/worktrunk/config.toml.new[107m [0m [1mindex d95d100..ceb381d 100644[m[107m [0m [1m--- a[TEMP_HOME]/.config/worktrunk/config.tomldiff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_displays_project_commit_generation_deprecations.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_displays_project_commit_generation_deprecations.snapindex 6910d44b9..4e30e8614 100644--- a/tests/snapshots/integration__integration_tests__config_show__config_show_displays_project_commit_generation_deprecations.snap+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_displays_project_commit_generation_deprecations.snap@@ -43,7 +43,8 @@ exit_code: 0----- stderr -----[36mUSER CONFIG[39m ~/.config/worktrunk/config.toml[33m▲[39m [33mUser config uses deprecated config sections: [projects."github.com/example/repo".commit-generation] → [projects."github.com/example/repo".commit.generation][39m-[2m↳[22m [2mRun [90mwt config update[39m to apply[22m+[2m↳[22m [2mTo apply:[22m+[107m [0m [2m[0m[2m[34mwt[0m[2m config update[107m [0m [1mdiff --git a[TEMP_HOME]/.config/worktrunk/config.toml b[TEMP_HOME]/.config/worktrunk/config.toml.new[107m [0m [1mindex de80729..131a2fd 100644[m[107m [0m [1m--- a[TEMP_HOME]/.config/worktrunk/config.tomldiff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_from_linked_worktree_shows_main_worktree_hint.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_from_linked_worktree_shows_main_worktree_hint.snapindex e8ad9f755..68948ca48 100644--- a/tests/snapshots/integration__integration_tests__config_show__config_show_from_linked_worktree_shows_main_worktree_hint.snap+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_from_linked_worktree_shows_main_worktree_hint.snap@@ -46,7 +46,8 @@ exit_code: 0[36mPROJECT CONFIG[39m [PROJECT_ID][33m▲[39m [33mProject config uses deprecated template variables: [2mmain_worktree[22m → [1mrepo[22m[39m-[2m↳[22m [2mRun [90mwt config update[39m from main worktree to apply[22m+[2m↳[22m [2mTo apply:[22m+[107m [0m [2m[0m[2m[34mwt[0m[2m [0m[2m[36m-C[0m[2m _REPO_ config update[2m○[22m Current config:[107m [0m post-create = [32m"ln -sf {{ main_worktree }}/node_modules"diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_suggests_user_config_for_commit_generation.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_suggests_user_config_for_commit_generation.snapindex f09e8d1c2..87389ed8c 100644--- a/tests/snapshots/integration__integration_tests__config_show__config_show_suggests_user_config_for_commit_generation.snap+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_suggests_user_config_for_commit_generation.snap@@ -47,7 +47,8 @@ exit_code: 0[36mPROJECT CONFIG[39m _REPO_/.config/wt.toml[33m▲[39m [33mProject config uses deprecated config sections: [commit-generation] → [commit.generation][39m-[2m↳[22m [2mRun [90mwt config update[39m to apply[22m+[2m↳[22m [2mTo apply:[22m+[107m [0m [2m[0m[2m[34mwt[0m[2m config update[107m [0m [1mdiff --git a_REPO_/.config/wt.toml b_REPO_/.config/wt.toml.new[m[107m [0m [1mindex 074c30f..bcaf404 100644[m[107m [0m [1m--- a_REPO_/.config/wt.toml[m