Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
chore: Improve code quality and simplify codebase
Maximilian Roos7aea677de87e
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yamlindex 08f8e2273..385c6353d 100644--- a/.pre-commit-config.yaml+++ b/.pre-commit-config.yaml@@ -23,7 +23,7 @@ repos:rev: v1.0.1hooks:- id: clippy- stages: [manual]+ args: ["--", "-D", "warnings"]- repo: https://github.com/tcort/markdown-link-checkrev: v3.14.1hooks:diff --git a/src/commands/command_approval.rs b/src/commands/command_approval.rsindex a23c12360..8be23c170 100644--- a/src/commands/command_approval.rs+++ b/src/commands/command_approval.rs@@ -80,11 +80,9 @@ pub fn approve_command_batch(}}- if updated {- if let Err(e) = fresh_config.save() {- log_approval_warning("Failed to save command approval", e);- eprintln!("You will be prompted again next time.");- }+ if updated && let Err(e) = fresh_config.save() {+ log_approval_warning("Failed to save command approval", e);+ eprintln!("You will be prompted again next time.");}Ok(true)diff --git a/src/commands/command_executor.rs b/src/commands/command_executor.rsindex eabc90099..2414a6066 100644--- a/src/commands/command_executor.rs+++ b/src/commands/command_executor.rs@@ -76,19 +76,19 @@ wherelet mut prepared = Vec::new();- if !auto_trust {- if !approve_command_batch(+ if !auto_trust+ && !approve_command_batch(&commands,&project_id,ctx.config,ctx.force,approval_context,- )? {- for (name, command) in &commands {- on_skip(name, command);- }- return Err(GitError::CommandFailed(String::new()));+ )?+ {+ for (name, command) in &commands {+ on_skip(name, command);}+ return Err(GitError::CommandFailed(String::new()));}for (name, command) in commands {diff --git a/src/commands/merge.rs b/src/commands/merge.rsindex 427df27b6..b30b4d259 100644--- a/src/commands/merge.rs+++ b/src/commands/merge.rs@@ -138,7 +138,7 @@ fn format_merge_summary(let bold = AnstyleStyle::new().bold();let dim = AnstyleStyle::new().dimmed();- let mut output = format!("Merge complete\n\n");+ let mut output = "Merge complete\n\n".to_string();// Show what was mergedoutput.push_str(&format!(diff --git a/src/commands/worktree.rs b/src/commands/worktree.rsindex 8752c08d5..71a1f1977 100644--- a/src/commands/worktree.rs+++ b/src/commands/worktree.rs@@ -105,7 +105,7 @@ use worktrunk::config::{ProjectConfig, WorktrunkConfig};use worktrunk::git::{GitError, Repository};use worktrunk::styling::{ADDITION, AnstyleStyle, CYAN, CYAN_BOLD, DELETION, ERROR, ERROR_EMOJI, GREEN, GREEN_BOLD, HINT,- HINT_EMOJI, WARNING, WARNING_EMOJI, eprint, eprintln, format_with_gutter, println,+ HINT_EMOJI, WARNING, WARNING_EMOJI, eprint, eprintln, format_with_gutter,};use super::command_executor::{CommandContext, prepare_project_commands};diff --git a/src/llm.rs b/src/llm.rsindex d9107a19e..30dfb9971 100644--- a/src/llm.rs+++ b/src/llm.rs@@ -7,21 +7,21 @@ pub fn generate_commit_message(commit_generation_config: &CommitGenerationConfig,) -> Result<String, GitError> {// Check if commit generation is configured (non-empty command)- if let Some(ref command) = commit_generation_config.command {- if !command.trim().is_empty() {- // Commit generation is explicitly configured - fail if it doesn't work- return try_generate_commit_message(- custom_instruction,- command,- &commit_generation_config.args,- )- .map_err(|e| {- GitError::CommandFailed(format!(- "Commit generation command '{}' failed: {}",- command, e- ))- });- }+ if let Some(ref command) = commit_generation_config.command+ && !command.trim().is_empty()+ {+ // Commit generation is explicitly configured - fail if it doesn't work+ return try_generate_commit_message(+ custom_instruction,+ command,+ &commit_generation_config.args,+ )+ .map_err(|e| {+ GitError::CommandFailed(format!(+ "Commit generation command '{}' failed: {}",+ command, e+ ))+ });}// Fallback: simple deterministic commit message (only when not configured)@@ -146,16 +146,16 @@ pub fn generate_squash_message(commit_generation_config: &CommitGenerationConfig,) -> Result<String, Box<dyn std::error::Error>> {// Check if commit generation is configured (non-empty command)- if let Some(ref command) = commit_generation_config.command {- if !command.trim().is_empty() {- // Commit generation is explicitly configured - fail if it doesn't work- return try_generate_llm_message(- target_branch,- subjects,- command,- &commit_generation_config.args,- );- }+ if let Some(ref command) = commit_generation_config.command+ && !command.trim().is_empty()+ {+ // Commit generation is explicitly configured - fail if it doesn't work+ return try_generate_llm_message(+ target_branch,+ subjects,+ command,+ &commit_generation_config.args,+ );}// Fallback: deterministic commit message (only when not configured)diff --git a/src/output/directive.rs b/src/output/directive.rsindex 4952c8ac3..7b927b756 100644--- a/src/output/directive.rs+++ b/src/output/directive.rs@@ -54,10 +54,6 @@ impl DirectiveOutput {io::stdout().flush()?;io::stderr().flush()}-- pub fn is_interactive(&self) -> bool {- false- }}impl Default for DirectiveOutput {diff --git a/src/output/global.rs b/src/output/global.rsindex 785960554..032119092 100644--- a/src/output/global.rs+++ b/src/output/global.rs@@ -112,14 +112,6 @@ pub fn flush() -> io::Result<()> {})}-/// Check if interactive mode-pub fn is_interactive() -> bool {- OUTPUT_CONTEXT.with(|ctx| match &*ctx.borrow() {- OutputHandler::Interactive(i) => i.is_interactive(),- OutputHandler::Directive(d) => d.is_interactive(),- })-}-#[cfg(test)]mod tests {use super::*;@@ -128,10 +120,10 @@ mod tests {fn test_mode_switching() {// Default is interactiveinitialize(OutputMode::Interactive);- assert!(is_interactive());+ // Just verify initialize doesn't panic// Switch to directiveinitialize(OutputMode::Directive);- assert!(!is_interactive());+ // Just verify initialize doesn't panic}}diff --git a/src/output/interactive.rs b/src/output/interactive.rsindex 357e63796..2facd997e 100644--- a/src/output/interactive.rs+++ b/src/output/interactive.rs@@ -37,14 +37,10 @@ impl InteractiveOutput {pub fn execute(&mut self, command: String) -> io::Result<()> {// Execute command in the target directory- let exec_dir = self- .target_dir- .as_ref()- .map(|p| p.as_path())- .unwrap_or_else(|| Path::new("."));+ let exec_dir = self.target_dir.as_deref().unwrap_or_else(|| Path::new("."));crate::output::execute_command_in_worktree(exec_dir, &command)- .map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string()))+ .map_err(|e| io::Error::other(e.to_string()))}pub fn flush(&mut self) -> io::Result<()> {@@ -52,10 +48,6 @@ impl InteractiveOutput {io::stderr().flush()?;Ok(())}-- pub fn is_interactive(&self) -> bool {- true- }}impl Default for InteractiveOutput {diff --git a/src/output/mod.rs b/src/output/mod.rsindex 41d1e19dd..725dc1ba8 100644--- a/src/output/mod.rs+++ b/src/output/mod.rs@@ -62,9 +62,7 @@ pub mod handlers;pub mod interactive;// Re-export the public API-pub use global::{- OutputMode, change_directory, execute, flush, initialize, is_interactive, progress, success,-};+pub use global::{OutputMode, change_directory, execute, flush, initialize, progress, success};// Re-export output handlerspub use handlers::{execute_command_in_worktree, handle_remove_output, handle_switch_output};