Skip to content

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

refactor(config): fold require_user_config_path into require_config_path (#2872)

Maximilian Roosd1f65ec629ee
diff --git a/src/commands/config/create.rs b/src/commands/config/create.rs
index d4b10a78a..330e83a4f 100644
--- a/src/commands/config/create.rs
+++ b/src/commands/config/create.rs
@@ -5,12 +5,11 @@
use anyhow::Context;
use color_print::cformat;
use std::path::PathBuf;
+use worktrunk::config::require_config_path;
use worktrunk::git::Repository;
use worktrunk::path::format_path_for_display;
use worktrunk::styling::{eprintln, hint_message, info_message, success_message};
-use super::state::require_user_config_path;
-
/// Example user configuration file content (displayed in help with values uncommented)
const USER_CONFIG_EXAMPLE: &str = include_str!("../../../dev/config.example.toml");
@@ -47,9 +46,7 @@ pub fn handle_config_create(project: bool) -> anyhow::Result<()> {
let config_path = repo
.project_config_path()?
.context("Cannot determine project config location — no worktree found")?;
- let user_config_exists = require_user_config_path()
- .map(|p| p.exists())
- .unwrap_or(false);
+ let user_config_exists = require_config_path().map(|p| p.exists()).unwrap_or(false);
create_config_file(
config_path,
PROJECT_CONFIG_EXAMPLE,
@@ -69,7 +66,7 @@ pub fn handle_config_create(project: bool) -> anyhow::Result<()> {
.map(|path| path.exists())
.unwrap_or(false);
create_config_file(
- require_user_config_path()?,
+ require_config_path()?,
USER_CONFIG_EXAMPLE,
"User config",
&["Edit this file to customize worktree paths and LLM settings"],
diff --git a/src/commands/config/mod.rs b/src/commands/config/mod.rs
index ccb08a131..fcd165eff 100644
--- a/src/commands/config/mod.rs
+++ b/src/commands/config/mod.rs
@@ -38,7 +38,6 @@ mod tests {
use super::create::comment_out_config;
use super::show::{render_ci_tool_status, warn_unknown_keys};
- use super::state::require_user_config_path;
// ==================== comment_out_config tests ====================
@@ -233,29 +232,4 @@ mod tests {
render_ci_tool_status(&mut out, "glab", "GitLab", true, true).unwrap();
assert_snapshot!(out, @"✓ glab installed & authenticated");
}
-
- // ==================== require_user_config_path tests ====================
-
- #[test]
- fn test_require_user_config_path_returns_ok() {
- // In a normal environment, require_user_config_path should succeed
- let result = require_user_config_path();
- assert!(result.is_ok());
- let path = result.unwrap();
- assert!(path.ends_with("worktrunk/config.toml"));
- }
-
- #[test]
- fn test_require_user_config_path_matches_config_path() {
- // Verify that config create/show path matches config loading path.
- // This was the root cause of #1134: the two paths diverged on Windows
- // when XDG_CONFIG_HOME was set because config create had its own
- // XDG/HOME resolution that differed from config loading.
- let create_path = require_user_config_path().unwrap();
- let load_path = worktrunk::config::config_path().unwrap();
- assert_eq!(
- create_path, load_path,
- "config create path and config loading path must be identical"
- );
- }
}
diff --git a/src/commands/config/show.rs b/src/commands/config/show.rs
index 375d0dda7..0452bf111 100644
--- a/src/commands/config/show.rs
+++ b/src/commands/config/show.rs
@@ -10,7 +10,7 @@ use std::path::{Path, PathBuf};
use anyhow::Context;
use color_print::cformat;
use worktrunk::config::{
- ProjectConfig, UserConfig, default_system_config_path, system_config_path,
+ ProjectConfig, UserConfig, default_system_config_path, require_config_path, system_config_path,
};
use worktrunk::git::{CiPlatform, ErrorExt, Repository};
use worktrunk::path::format_path_for_display;
@@ -21,7 +21,6 @@ use worktrunk::styling::{
hint_message, info_message, success_message, warning_message,
};
-use super::state::require_user_config_path;
use crate::cli::{SwitchFormat, version_str};
use crate::commands::configure_shell::{ConfigAction, ConfigureResult, scan_shell_configs};
use crate::commands::list::ci_status::CiToolsStatus;
@@ -96,7 +95,7 @@ pub fn handle_config_show(full: bool, format: SwitchFormat) -> anyhow::Result<()
/// JSON output for config show: paths, existence, and parsed config contents.
fn handle_config_show_json() -> anyhow::Result<()> {
- let user_path = require_user_config_path()?;
+ let user_path = require_config_path()?;
let user_exists = user_path.exists();
let user_config = if user_exists {
Some(serde_json::to_value(&UserConfig::load()?)?)
@@ -583,7 +582,7 @@ fn render_system_config(out: &mut String) -> anyhow::Result<bool> {
}
fn render_user_config(out: &mut String, has_system_config: bool) -> anyhow::Result<()> {
- let config_path = require_user_config_path()?;
+ let config_path = require_config_path()?;
writeln!(
out,
diff --git a/src/commands/config/state.rs b/src/commands/config/state.rs
index a6e2208e1..e04b29c98 100644
--- a/src/commands/config/state.rs
+++ b/src/commands/config/state.rs
@@ -42,12 +42,11 @@
//! under a single reserved subdirectory rather than adding sibling top-level dirs.
use std::fmt::Write as _;
-use std::path::{Path, PathBuf};
+use std::path::Path;
use anyhow::Context;
use color_print::cformat;
use path_slash::PathExt as _;
-use worktrunk::config::config_path;
use worktrunk::git::{BranchRef, Repository, sha_cache};
use worktrunk::path::format_path_for_display;
use worktrunk::styling::{
@@ -95,17 +94,6 @@ fn picker_preview_clear(repo: &Repository) -> anyhow::Result<usize> {
}
}
-// ==================== Path Helpers ====================
-
-/// Get the user config path, or error if it cannot be determined.
-///
-/// Delegates to `config_path()` so that `config create` and `config show`
-/// resolve the same path that config loading uses — including any CLI
-/// (`--config`) or environment variable (`WORKTRUNK_CONFIG_PATH`) overrides.
-pub fn require_user_config_path() -> anyhow::Result<PathBuf> {
- config_path().context("Cannot determine config directory")
-}
-
// ==================== Log Management ====================
/// Top-level files created by `-vv` under `wt_logs_dir()`.