Skip to content

Commit a86d15e

Browse files
worktrunk-botclaude
andcommitted
refactor(bare-repo): drop dead per-project setter, fix shell-command highlighting
`set_project_worktree_path` lost its sole production caller when `offer_bare_repo_worktree_path_fix` switched to writing `worktrunk.worktree-path` to git config — remove the setter and its two tests. Reading the per-remote scope still works via load → parse. Use `format_bash_with_gutter` instead of `format_toml` for the `git config worktrunk.worktree-path "…"` snippet shown in the non-interactive warning — it's a shell command, not a TOML fragment. The TOML-shaped `worktrunk.worktree-path = "…"` preview/accepted messages keep `format_toml`. Co-Authored-By: Claude Opus 4.7 <[email protected]>
1 parent c18d653 commit a86d15e

3 files changed

Lines changed: 3 additions & 81 deletions

File tree

‎src/commands/worktree/resolve.rs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ use worktrunk::config::UserConfig;
1212
use worktrunk::git::{Repository, ResolvedWorktree};
1313
use worktrunk::path::{format_path_for_display, paths_match};
1414
use worktrunk::styling::{
15-
eprintln, format_toml, hint_message, info_message, success_message, warning_message,
15+
eprintln, format_bash_with_gutter, format_toml, hint_message, info_message, success_message,
16+
warning_message,
1617
};
1718

1819
use crate::output::prompt::{PromptResponse, prompt_yes_no_preview};
@@ -275,7 +276,7 @@ pub fn offer_bare_repo_worktree_path_fix(
275276
);
276277
eprintln!(
277278
"{}",
278-
format_toml(&format!(
279+
format_bash_with_gutter(&format!(
279280
"git config worktrunk.worktree-path \"{BARE_REPO_WORKTREE_PATH}\""
280281
))
281282
);

‎src/config/user/mutation.rs‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -128,25 +128,6 @@ impl UserConfig {
128128
})
129129
}
130130

131-
/// Set worktree-path for a specific project and save.
132-
///
133-
/// Creates the project entry if it doesn't exist.
134-
pub fn set_project_worktree_path(
135-
&mut self,
136-
project: &str,
137-
worktree_path: String,
138-
config_path: &std::path::Path,
139-
) -> Result<(), ConfigError> {
140-
self.with_locked_mutation(config_path, |config| {
141-
let entry = config.projects.entry(project.to_string()).or_default();
142-
if entry.worktree_path.as_ref() == Some(&worktree_path) {
143-
return false;
144-
}
145-
entry.worktree_path = Some(worktree_path);
146-
true
147-
})
148-
}
149-
150131
/// Set commit generation command and save.
151132
///
152133
/// Sets `[commit.generation] command = ...` in the user config.

‎src/config/user/tests.rs‎

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -567,32 +567,6 @@ worktree-path = "../{{ main_worktree }}.{{ branch }}"
567567
assert!(!config.skip_shell_integration_prompt);
568568
}
569569

570-
#[test]
571-
fn test_set_project_worktree_path() {
572-
let dir = tempfile::tempdir().unwrap();
573-
let config_path = dir.path().join("config.toml");
574-
std::fs::write(&config_path, "# empty config\n").unwrap();
575-
576-
let mut config = UserConfig::default();
577-
config
578-
.set_project_worktree_path(
579-
"github.com/user/repo",
580-
"../{{ branch | sanitize }}".to_string(),
581-
&config_path,
582-
)
583-
.unwrap();
584-
585-
assert_eq!(
586-
config.worktree_path_for_project("github.com/user/repo"),
587-
"../{{ branch | sanitize }}"
588-
);
589-
590-
// Verify it was saved to disk
591-
let content = std::fs::read_to_string(&config_path).unwrap();
592-
assert!(content.contains("[projects.\"github.com/user/repo\"]"));
593-
assert!(content.contains("worktree-path"));
594-
}
595-
596570
// =========================================================================
597571
// Merge trait tests
598572
// =========================================================================
@@ -3269,40 +3243,6 @@ fn test_save_to_existing_file_preserves_inline_table_formatting() {
32693243
// mutation.rs — additional coverage
32703244
// =========================================================================
32713245

3272-
#[test]
3273-
fn test_set_project_worktree_path_noop_when_unchanged() {
3274-
// Covers the `return false` early-exit in set_project_worktree_path's
3275-
// mutator: when the path already matches, no save happens. We verify
3276-
// this by checking that the file content is byte-identical across a
3277-
// redundant call.
3278-
let dir = tempfile::tempdir().unwrap();
3279-
let config_path = dir.path().join("config.toml");
3280-
std::fs::write(&config_path, "# keep\n").unwrap();
3281-
3282-
let mut config = UserConfig::default();
3283-
config
3284-
.set_project_worktree_path("user/repo", "../custom".to_string(), &config_path)
3285-
.unwrap();
3286-
3287-
let after_first = std::fs::read_to_string(&config_path).unwrap();
3288-
// Sanity: first call actually wrote the value
3289-
assert!(after_first.contains("../custom"), "{after_first}");
3290-
3291-
// Second call with identical value should be a no-op — reload_from
3292-
// refreshes self from disk, the mutator compares equal and returns
3293-
// false, so save is skipped.
3294-
let mut config2 = UserConfig::default();
3295-
config2
3296-
.set_project_worktree_path("user/repo", "../custom".to_string(), &config_path)
3297-
.unwrap();
3298-
3299-
let after_second = std::fs::read_to_string(&config_path).unwrap();
3300-
assert_eq!(
3301-
after_first, after_second,
3302-
"unchanged value should not rewrite the file"
3303-
);
3304-
}
3305-
33063246
#[test]
33073247
fn test_set_skip_shell_integration_prompt_noop_on_second_call() {
33083248
// Covers the `return false` early-exit in set_skip_shell_integration_prompt's

0 commit comments

Comments
 (0)