Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
feat: Add `require_global_config_path` helper
Maximilian Roos823869e8dd8c
diff --git a/src/commands/config.rs b/src/commands/config.rsindex ac0fb39f5..ccc107d85 100644--- a/src/commands/config.rs+++ b/src/commands/config.rs@@ -42,11 +42,7 @@ fn comment_out_config(content: &str) -> String {/// Handle the config create commandpub fn handle_config_create() -> anyhow::Result<()> {- let config_path = get_user_config_path().ok_or_else(|| {- anyhow::anyhow!(- "Cannot determine config directory. Set $HOME or $XDG_CONFIG_HOME environment variable"- )- })?;+ let config_path = require_user_config_path()?;// Check if file already existsif config_path.exists() {@@ -107,12 +103,7 @@ pub fn handle_config_show() -> anyhow::Result<()> {}fn render_user_config(out: &mut String) -> anyhow::Result<()> {- // Get config path- let config_path = get_user_config_path().ok_or_else(|| {- anyhow::anyhow!(- "Cannot determine config directory. Set $HOME or $XDG_CONFIG_HOME environment variable"- )- })?;+ let config_path = require_user_config_path()?;writeln!(out,@@ -392,6 +383,14 @@ fn get_user_config_path() -> Option<PathBuf> {Some(strategy.config_dir().join("worktrunk").join("config.toml"))}+fn require_user_config_path() -> anyhow::Result<PathBuf> {+ get_user_config_path().ok_or_else(|| {+ anyhow::anyhow!(+ "Cannot determine config directory. Set $HOME or $XDG_CONFIG_HOME environment variable"+ )+ })+}+/// Handle the config status set commandpub fn handle_config_status_set(value: String, branch: Option<String>) -> anyhow::Result<()> {let repo = Repository::current();diff --git a/src/commands/configure_shell.rs b/src/commands/configure_shell.rsindex 541e21c36..853fbe60f 100644--- a/src/commands/configure_shell.rs+++ b/src/commands/configure_shell.rs@@ -429,8 +429,7 @@ fn configure_fish_file(// even if the specific wt.fish file doesn'tif !explicit_shell && !path.exists() {// Check if parent directory exists- let parent_exists = path.parent().map(|p| p.exists()).unwrap_or(false);- if !parent_exists {+ if !path.parent().is_some_and(|p| p.exists()) {return Ok(None);}}diff --git a/src/commands/list/collect.rs b/src/commands/list/collect.rsindex b43620519..bcca08409 100644--- a/src/commands/list/collect.rs+++ b/src/commands/list/collect.rs@@ -723,7 +723,7 @@ fn sort_worktrees(let mut indexed: Vec<_> = worktrees.into_iter().enumerate().collect();indexed.sort_by_key(|(idx, wt)| {- let priority = if current_path.map(|cp| &wt.path == cp).unwrap_or(false) {+ let priority = if current_path.is_some_and(|cp| &wt.path == cp) {0 // Current first} else if wt.path == main_worktree.path {1 // Main seconddiff --git a/src/commands/list/render.rs b/src/commands/list/render.rsindex cd031f1ea..c68b00bdd 100644--- a/src/commands/list/render.rs+++ b/src/commands/list/render.rs@@ -377,8 +377,8 @@ impl LayoutConfig {let branch = item.branch_name();let wt_data = item.worktree_data();let is_main = item.is_main();- let is_current = wt_data.map(|d| d.is_current).unwrap_or(false);- let is_previous = wt_data.map(|d| d.is_previous).unwrap_or(false);+ let is_current = wt_data.is_some_and(|d| d.is_current);+ let is_previous = wt_data.is_some_and(|d| d.is_previous);let shortened_path = item.worktree_path().map(|p| shorten_path(p, &self.common_prefix))@@ -458,12 +458,10 @@ impl<'a> ListRowContext<'a> {let head = item.head();// Use stored values for worktrees, compute for branches- let is_current = worktree_data.map(|d| d.is_current).unwrap_or(false);+ let is_current = worktree_data.is_some_and(|d| d.is_current);let is_previous = worktree_data.map(|d| d.is_previous).unwrap_or_else(|| {// Branches don't have WorktreeData, compute from previous_branch- previous_branch- .map(|prev| item.branch.as_deref() == Some(prev))- .unwrap_or(false)+ previous_branch.is_some_and(|prev| item.branch.as_deref() == Some(prev))});let mut ctx = Self {diff --git a/src/git/error.rs b/src/git/error.rsindex 223ed3cc9..9824810ea 100644--- a/src/git/error.rs+++ b/src/git/error.rs@@ -11,7 +11,7 @@use std::path::PathBuf;-use color_print::cwrite;+use color_print::{cformat, cwrite};use super::HookType;use crate::path::format_path_for_display;@@ -216,7 +216,6 @@ impl std::fmt::Display for GitError {base_branch,error,} => {- use color_print::cformat;let base_suffix = base_branch.as_ref().map(|base| format!(" from base <bold>{base}</>"))@@ -232,7 +231,6 @@ impl std::fmt::Display for GitError {path,error,} => {- use color_print::cformat;let path_display = format_path_for_display(path);let header = cformat!("{ERROR_EMOJI} <red>Failed to remove worktree for <bold>{branch}</> at <bold>{path_display}</></>"@@ -306,7 +304,6 @@ impl std::fmt::Display for GitError {}GitError::PushFailed { error } => {- use color_print::cformat;let header = cformat!("{ERROR_EMOJI} <red>Push failed</>");write!(f, "{}", format_error_block(header, error))}@@ -319,7 +316,6 @@ impl std::fmt::Display for GitError {}GitError::LlmCommandFailed { command, error } => {- use color_print::cformat;let error_header =cformat!("{ERROR_EMOJI} <red>Commit generation command failed</>");let error_block = format_error_block(error_header, error);