Skip to content

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

fix: suppress worktree-path hint when project-specific config exists (#1941)

worktrunk-bot017f5a76d0ad
diff --git a/src/config/user/accessors.rs b/src/config/user/accessors.rs
index a35899a86..1a5658a03 100644
--- a/src/config/user/accessors.rs
+++ b/src/config/user/accessors.rs
@@ -49,11 +49,19 @@ impl UserConfig {
.unwrap_or_else(default_worktree_path)
}
- /// Returns true if the user has explicitly set a custom worktree-path.
+ /// Returns true if the user has explicitly set a custom global worktree-path.
pub fn has_custom_worktree_path(&self) -> bool {
self.configs.worktree_path.is_some()
}
+ /// Returns true if the given project has an explicit worktree-path override.
+ pub fn has_project_worktree_path(&self, project: &str) -> bool {
+ self.projects
+ .get(project)
+ .and_then(|p| p.overrides.worktree_path.as_ref())
+ .is_some()
+ }
+
/// Returns the worktree path template for a specific project.
///
/// Checks project-specific config first, falls back to global worktree-path,
diff --git a/src/output/handlers.rs b/src/output/handlers.rs
index 98dad7024..657f38721 100644
--- a/src/output/handlers.rs
+++ b/src/output/handlers.rs
@@ -334,7 +334,13 @@ fn maybe_print_worktree_path_hint(created_branch: bool) {
if let Ok(repo) = worktrunk::git::Repository::current() {
let has_custom_config = UserConfig::load()
- .map(|c| c.has_custom_worktree_path())
+ .map(|c| {
+ c.has_custom_worktree_path()
+ || repo
+ .project_identifier()
+ .ok()
+ .is_some_and(|p| c.has_project_worktree_path(&p))
+ })
.unwrap_or(false);
if !has_custom_config && !repo.has_shown_hint("worktree-path") {
let hint = hint_message(cformat!(
diff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rs
index cb6c826d7..c9be8d2fb 100644
--- a/tests/integration_tests/switch.rs
+++ b/tests/integration_tests/switch.rs
@@ -1560,6 +1560,67 @@ fn test_switch_create_no_hint_with_custom_worktree_path(repo: TestRepo) {
);
}
+/// Test that the worktree-path hint is suppressed when a project-specific
+/// worktree-path is configured (not just a global one).
+///
+/// Regression test for #1939: `has_custom_worktree_path()` only checked the
+/// global `worktree-path` setting, causing a misleading hint even when a
+/// project-specific template was configured.
+#[rstest]
+fn test_switch_create_no_hint_with_project_specific_worktree_path(repo: TestRepo) {
+ // Set origin to a GitHub URL so the project identifier matches
+ let bare_url = String::from_utf8_lossy(
+ &repo
+ .git_command()
+ .args(["config", "remote.origin.url"])
+ .run()
+ .unwrap()
+ .stdout,
+ )
+ .trim()
+ .to_string();
+
+ repo.run_git(&[
+ "remote",
+ "set-url",
+ "origin",
+ "https://github.com/test-org/test-repo.git",
+ ]);
+
+ // Redirect GitHub URL to local bare remote for actual git operations
+ repo.run_git(&[
+ "config",
+ &format!("url.{}.insteadOf", bare_url),
+ "https://github.com/test-org/test-repo.git",
+ ]);
+
+ // Set project-specific worktree-path (no global worktree-path set)
+ repo.write_test_config(
+ r#"
+[projects."github.com/test-org/test-repo"]
+worktree-path = "{{ repo_path }}/../{{ branch | sanitize }}"
+"#,
+ );
+
+ let output = repo
+ .wt_command()
+ .args(["switch", "--create", "project-feature"])
+ .output()
+ .unwrap();
+
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ assert!(
+ output.status.success(),
+ "switch --create should succeed, stderr: {stderr}"
+ );
+
+ // Hint should be suppressed when project-specific worktree-path exists
+ assert!(
+ !stderr.contains("customize worktree locations"),
+ "Hint should be suppressed when project has custom worktree-path. stderr: {stderr}"
+ );
+}
+
// ============================================================================
// PR Syntax Tests (pr:<number>)
// ============================================================================
diff --git a/tests/snapshots/integration__integration_tests__bare_repository__bare_repo_prompt_pty__bare_repo_prompt_accept.snap b/tests/snapshots/integration__integration_tests__bare_repository__bare_repo_prompt_pty__bare_repo_prompt_accept.snap
index cdc10fbe7..0986ffdcc 100644
--- a/tests/snapshots/integration__integration_tests__bare_repository__bare_repo_prompt_pty__bare_repo_prompt_accept.snap
+++ b/tests/snapshots/integration__integration_tests__bare_repository__bare_repo_prompt_pty__bare_repo_prompt_accept.snap
@@ -10,6 +10,5 @@ expression: "&output"
↳ To set globally, add to [TEMP]/test-config.toml
✓ Created branch feature and worktree @ [TEMP]/project/feature
-↳ To customize worktree locations, run wt config create
▲ Cannot change directory — shell integration not installed
↳ To enable automatic cd, run wt config shell install