Skip to content

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

refactor: move inline imports to module level (batch 4) (#822)

Maximilian Roosccb27fe9a3b6
diff --git a/src/commands/config/show.rs b/src/commands/config/show.rs
index b53049e96..291efc29c 100644
--- a/src/commands/config/show.rs
+++ b/src/commands/config/show.rs
@@ -3,6 +3,7 @@
//! Functions for displaying user config, project config, shell status,
//! diagnostics, and runtime info.
+use std::collections::HashMap;
use std::fmt::Write as _;
use std::path::PathBuf;
@@ -14,6 +15,7 @@ use worktrunk::config::{
use worktrunk::git::Repository;
use worktrunk::path::format_path_for_display;
use worktrunk::shell::{Shell, scan_for_detection_details};
+use worktrunk::shell_exec::Cmd;
use worktrunk::styling::{
error_message, format_bash_with_gutter, format_heading, format_toml, format_with_gutter,
hint_message, info_message, success_message, warning_message,
@@ -22,6 +24,7 @@ use worktrunk::styling::{
use super::state::require_user_config_path;
use crate::cli::version_str;
use crate::commands::configure_shell::{ConfigAction, scan_shell_configs};
+use crate::commands::list::ci_status::{CiPlatform, CiToolsStatus, get_platform_for_repo};
use crate::help_pager::show_help_in_pager;
use crate::llm::test_commit_generation;
use crate::output;
@@ -66,8 +69,6 @@ pub fn handle_config_show(full: bool) -> anyhow::Result<()> {
/// Check if Claude Code CLI is available
fn is_claude_available() -> bool {
- use worktrunk::shell_exec::Cmd;
-
Cmd::new("claude")
.arg("--version")
.run()
@@ -99,8 +100,6 @@ fn is_plugin_installed() -> bool {
/// Get the git version string (e.g., "2.47.1")
fn get_git_version() -> Option<String> {
- use worktrunk::shell_exec::Cmd;
-
let output = Cmd::new("git").arg("--version").run().ok()?;
if !output.status.success() {
return None;
@@ -119,8 +118,6 @@ fn get_git_version() -> Option<String> {
/// Returns true if compinit is NOT enabled (i.e., user needs to add it).
/// Returns false if compinit is enabled or we can't determine (fail-safe: don't warn).
fn check_zsh_compinit_missing() -> bool {
- use worktrunk::shell_exec::Cmd;
-
// Allow tests to bypass this check since zsh subprocess behavior varies across CI envs
if std::env::var("WORKTRUNK_TEST_COMPINIT_CONFIGURED").is_ok() {
return false; // Assume compinit is configured
@@ -216,8 +213,6 @@ fn render_runtime_info(out: &mut String) -> anyhow::Result<()> {
/// Run full diagnostic checks (CI tools, commit generation) and render to buffer
fn render_diagnostics(out: &mut String) -> anyhow::Result<()> {
- use crate::commands::list::ci_status::{CiPlatform, CiToolsStatus, get_platform_for_repo};
-
writeln!(out, "{}", format_heading("DIAGNOSTICS", None))?;
// Check CI tool based on detected platform (with config override support)
@@ -356,9 +351,8 @@ fn render_user_config(out: &mut String) -> anyhow::Result<()> {
/// Generic over `C`, the config type where the keys were found. When an unknown
/// key belongs in `C::Other`, the warning includes a hint about where to move it.
pub(super) fn warn_unknown_keys<C: worktrunk::config::WorktrunkConfig>(
- unknown_keys: &std::collections::HashMap<String, toml::Value>,
+ unknown_keys: &HashMap<String, toml::Value>,
) -> String {
- use std::fmt::Write;
let mut out = String::new();
// Sort keys for deterministic output order
diff --git a/src/commands/list/ci_status/cache.rs b/src/commands/list/ci_status/cache.rs
index 1e4554d93..d560c055c 100644
--- a/src/commands/list/ci_status/cache.rs
+++ b/src/commands/list/ci_status/cache.rs
@@ -3,9 +3,12 @@
//! Caches CI status in `.git/wt-cache/ci-status/<branch>.json` to avoid
//! hitting API rate limits.
-use serde::{Deserialize, Serialize};
+use std::collections::hash_map::DefaultHasher;
use std::fs;
+use std::hash::{Hash, Hasher};
use std::path::{Path, PathBuf};
+
+use serde::{Deserialize, Serialize};
use worktrunk::git::Repository;
use worktrunk::path::sanitize_for_filename;
@@ -39,9 +42,6 @@ impl CachedCiStatus {
/// Different directories get different TTLs [30, 60) seconds, which spreads
/// out cache expirations when multiple statuslines run concurrently.
pub(crate) fn ttl_for_repo(repo_root: &Path) -> u64 {
- use std::collections::hash_map::DefaultHasher;
- use std::hash::{Hash, Hasher};
-
let mut hasher = DefaultHasher::new();
// Hash the path bytes directly for consistent TTL across string representations
repo_root.as_os_str().hash(&mut hasher);
diff --git a/src/commands/list/ci_status/mod.rs b/src/commands/list/ci_status/mod.rs
index fc9ff0a7c..5b3d02a07 100644
--- a/src/commands/list/ci_status/mod.rs
+++ b/src/commands/list/ci_status/mod.rs
@@ -8,6 +8,7 @@ mod github;
mod gitlab;
mod platform;
+use anstyle::{AnsiColor, Color, Style};
use serde::{Deserialize, Serialize, de::DeserializeOwned};
use worktrunk::git::Repository;
use worktrunk::shell_exec::Cmd;
@@ -176,8 +177,7 @@ impl CiStatus {
/// - Conflicts: Yellow
/// - NoCI: BrightBlack (dimmed)
/// - Error: Yellow (warning color)
- pub fn color(&self) -> anstyle::AnsiColor {
- use anstyle::AnsiColor;
+ pub fn color(&self) -> AnsiColor {
match self {
Self::Passed => AnsiColor::Green,
Self::Running => AnsiColor::Blue,
@@ -190,8 +190,7 @@ impl CiStatus {
impl PrStatus {
/// Get the style for this PR status (color + optional dimming for stale)
- pub fn style(&self) -> anstyle::Style {
- use anstyle::{Color, Style};
+ pub fn style(&self) -> Style {
let style = Style::new().fg_color(Some(Color::Ansi(self.ci_status.color())));
if self.is_stale { style.dimmed() } else { style }
}
diff --git a/src/commands/list/collect/mod.rs b/src/commands/list/collect/mod.rs
index 95d2a6bdf..200ce52ee 100644
--- a/src/commands/list/collect/mod.rs
+++ b/src/commands/list/collect/mod.rs
@@ -97,12 +97,14 @@ mod tasks;
mod types;
use anyhow::Context;
+use std::sync::Arc;
+
+use anstyle::Style;
use color_print::cformat;
use crossbeam_channel as chan;
use dunce::canonicalize;
use once_cell::sync::OnceCell;
use rayon::prelude::*;
-use std::sync::Arc;
use worktrunk::git::{Repository, WorktreeInfo};
use worktrunk::styling::{
INFO_SYMBOL, eprintln, format_with_gutter, hint_message, warning_message,
@@ -474,7 +476,6 @@ pub fn collect(
// Create progressive table if showing progress
let mut progressive_table = if show_progress {
- use anstyle::Style;
let dim = Style::new().dimmed();
// Build skeleton rows for both worktrees and branches
@@ -713,7 +714,6 @@ pub fn collect(
// Progressive mode only: update UI
if let Some(ref mut table) = progressive_table {
- use anstyle::Style;
let dim = Style::new().dimmed();
completed_results += 1;
diff --git a/src/commands/list/collect/results.rs b/src/commands/list/collect/results.rs
index 56ae5a641..ecb8eb638 100644
--- a/src/commands/list/collect/results.rs
+++ b/src/commands/list/collect/results.rs
@@ -4,6 +4,8 @@
//! - `drain_results()` - drain channel and apply results to items
//! - `apply_default()` - apply defaults for failed tasks
+use std::time::{Duration, Instant};
+
use crossbeam_channel as chan;
use worktrunk::git::LineDiff;
@@ -111,8 +113,6 @@ pub(super) fn drain_results(
expected_results: &ExpectedResults,
mut on_result: impl FnMut(usize, &mut ListItem, &StatusContext),
) -> DrainOutcome {
- use std::time::{Duration, Instant};
-
// Deadline for the entire drain operation (30 seconds should be more than enough)
let deadline = Instant::now() + Duration::from_secs(30);
diff --git a/src/commands/list/collect/tasks.rs b/src/commands/list/collect/tasks.rs
index 2cef932af..b52c04107 100644
--- a/src/commands/list/collect/tasks.rs
+++ b/src/commands/list/collect/tasks.rs
@@ -3,6 +3,9 @@
//! Contains the `Task` trait interface and all 15 task implementations that
//! compute various git operations for worktrees and branches.
+use std::net::{SocketAddr, TcpStream};
+use std::time::Duration;
+
use worktrunk::git::{LineDiff, Repository};
use super::super::ci_status::PrStatus;
@@ -616,9 +619,6 @@ impl Task for UrlStatusTask {
const KIND: TaskKind = TaskKind::UrlStatus;
fn compute(ctx: TaskContext) -> Result<TaskResult, TaskError> {
- use std::net::{SocketAddr, TcpStream};
- use std::time::Duration;
-
// URL already sent in spawning code; this task only checks port availability
let Some(ref url) = ctx.item_url else {
return Ok(TaskResult::UrlStatus {
diff --git a/src/commands/list/layout.rs b/src/commands/list/layout.rs
index 7088792ec..3a88ddaa7 100644
--- a/src/commands/list/layout.rs
+++ b/src/commands/list/layout.rs
@@ -170,13 +170,15 @@
//! - `fit_header()`: Ensures column width ≥ header width to prevent overflow
//! - `try_allocate()`: Attempts to allocate space, returns 0 if insufficient
-use crate::display::get_terminal_width;
-use anstyle::Style;
use std::collections::HashSet;
use std::path::{Path, PathBuf};
+
+use anstyle::Style;
use unicode_width::UnicodeWidthStr;
use worktrunk::styling::{ADDITION, DELETION, Stream, supports_hyperlinks};
+use crate::display::{get_terminal_width, shorten_path};
+
use super::collect::{TaskKind, parse_port_from_url};
use super::columns::{COLUMN_SPECS, ColumnKind, ColumnSpec, column_display_index};
@@ -850,10 +852,7 @@ pub fn calculate_layout_with_width(
let path_data_width = items
.iter()
.filter_map(|item| item.worktree_path())
- .map(|path| {
- use crate::display::shorten_path;
- shorten_path(path.as_path(), main_worktree_path).width()
- })
+ .map(|path| shorten_path(path.as_path(), main_worktree_path).width())
.max()
.unwrap_or(0);
let max_path_width = fit_header(ColumnKind::Path.header(), path_data_width);
diff --git a/src/commands/list/mod.rs b/src/commands/list/mod.rs
index e838f5a25..251d3f644 100644
--- a/src/commands/list/mod.rs
+++ b/src/commands/list/mod.rs
@@ -132,10 +132,16 @@ pub(crate) mod render;
mod spacing_test;
// Layout is calculated in collect.rs
+use std::collections::HashSet;
+
+use anstyle::Style;
use anyhow::Context;
use model::{ListData, ListItem};
use progressive::RenderMode;
use worktrunk::git::Repository;
+use worktrunk::styling::INFO_SYMBOL;
+
+use collect::TaskKind;
// Re-export for statusline and other consumers
pub use collect::{CollectOptions, build_worktree_item, populate_item};
@@ -149,14 +155,12 @@ pub fn handle_list(
render_mode: RenderMode,
config: &worktrunk::config::UserConfig,
) -> anyhow::Result<()> {
- use collect::TaskKind;
-
let repo = Repository::current()?;
// Build skip set based on flags
// Without --full: skip expensive operations (BranchDiff, CiStatus, WorkingTreeConflicts)
- let skip_tasks: std::collections::HashSet<TaskKind> = if show_full {
- std::collections::HashSet::new() // Compute everything
+ let skip_tasks: HashSet<TaskKind> = if show_full {
+ HashSet::new() // Compute everything
} else {
[
TaskKind::BranchDiff,
@@ -318,9 +322,6 @@ pub(crate) fn format_summary_message(
error_count: usize,
timed_out_count: usize,
) -> String {
- use anstyle::Style;
- use worktrunk::styling::INFO_SYMBOL;
-
let metrics = SummaryMetrics::from_items(items);
let dim = Style::new().dimmed();
let summary = metrics
diff --git a/src/commands/list/model/statusline_segment.rs b/src/commands/list/model/statusline_segment.rs
index 9b5f1392a..7dea5ae11 100644
--- a/src/commands/list/model/statusline_segment.rs
+++ b/src/commands/list/model/statusline_segment.rs
@@ -3,6 +3,9 @@
//! [`StatuslineSegment`] provides a way to format statusline output with
//! priority-based truncation when space is limited.
+use ansi_str::AnsiStr;
+use unicode_width::UnicodeWidthStr;
+
use crate::commands::list::columns::ColumnKind;
/// A segment of statusline output with priority for smart truncation.
@@ -46,8 +49,6 @@ impl StatuslineSegment {
/// Get the visible width of this segment (strips ANSI codes).
pub fn width(&self) -> usize {
- use ansi_str::AnsiStr;
- use unicode_width::UnicodeWidthStr;
self.content.ansi_strip().width()
}
diff --git a/src/commands/list/progressive.rs b/src/commands/list/progressive.rs
index 962f5059d..37c892e24 100644
--- a/src/commands/list/progressive.rs
+++ b/src/commands/list/progressive.rs
@@ -1,3 +1,5 @@
+use std::io::IsTerminal;
+
/// Rendering mode for list command
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RenderMode {
@@ -25,7 +27,6 @@ impl RenderMode {
}
// Priority 2: Auto-detect based on stdout TTY
- use std::io::IsTerminal;
if std::io::stdout().is_terminal() {
// TODO: Check for pager in environment
RenderMode::Progressive
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index 768824920..7b7b0c51b 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -21,7 +21,6 @@ pub(crate) mod statusline;
pub(crate) mod step_commands;
pub(crate) mod worktree;
-pub(crate) use command_approval::approve_hooks;
pub(crate) use config::{
handle_config_create, handle_config_show, handle_hints_clear, handle_hints_get,
handle_state_clear, handle_state_clear_all, handle_state_get, handle_state_set,
diff --git a/src/commands/select/items.rs b/src/commands/select/items.rs
index 159244f6e..f431e2a10 100644
--- a/src/commands/select/items.rs
+++ b/src/commands/select/items.rs
@@ -9,6 +9,7 @@ use std::sync::Arc;
use color_print::cformat;
use skim::prelude::*;
use worktrunk::git::Repository;
+use worktrunk::styling::INFO_SYMBOL;
use super::super::list::model::ListItem;
use super::log_formatter::{
@@ -153,8 +154,6 @@ impl WorktreeSkimItem {
/// Render Tab 1: Working tree preview (uncommitted changes vs HEAD)
/// Matches `wt list` "HEAD±" column
fn render_working_tree_preview(&self, width: usize) -> String {
- use worktrunk::styling::INFO_SYMBOL;
-
let Some(wt_info) = self.item.worktree_data() else {
// Branch without worktree - selecting will create one
let branch = self.item.branch_name();
@@ -176,8 +175,6 @@ impl WorktreeSkimItem {
/// Render Tab 3: Branch diff preview (line diffs in commits ahead of default branch)
/// Matches `wt list` "main…± (--full)" column
fn render_branch_diff_preview(&self, width: usize) -> String {
- use worktrunk::styling::INFO_SYMBOL;
-
let branch = self.item.branch_name();
let Ok(repo) = Repository::current() else {
return cformat!("{INFO_SYMBOL} <bold>{branch}</> has no commits ahead of main\n");
@@ -204,8 +201,6 @@ impl WorktreeSkimItem {
/// Render Tab 4: Upstream diff preview (ahead/behind vs tracking branch)
/// Matches `wt list` "Remote⇅" column
fn render_upstream_diff_preview(&self, width: usize) -> String {
- use worktrunk::styling::INFO_SYMBOL;
-
let branch = self.item.branch_name();
// Check if this branch has an upstream tracking branch
@@ -261,7 +256,6 @@ impl WorktreeSkimItem {
/// Render Tab 2: Log preview
fn render_log_preview(&self, width: usize, height: usize) -> String {
- use worktrunk::styling::INFO_SYMBOL;
// Minimum preview width to show timestamps (adds ~7 chars: space + 4-char time + space)
// Note: preview is typically 50% of terminal width, so 50 = 100-col terminal
const TIMESTAMP_WIDTH_THRESHOLD: usize = 50;
diff --git a/src/commands/select/log_formatter.rs b/src/commands/select/log_formatter.rs
index d567c9e37..7b21c65e9 100644
--- a/src/commands/select/log_formatter.rs
+++ b/src/commands/select/log_formatter.rs
@@ -3,9 +3,15 @@
//! Functions for processing and formatting git log output with diffstats and dimming.
use std::collections::{HashMap, HashSet};
+use std::fmt::Write;
+use ansi_str::AnsiStr;
+use unicode_width::UnicodeWidthStr;
use worktrunk::git::{Repository, parse_numstat_line};
use worktrunk::shell_exec::Cmd;
+use worktrunk::styling::{ADDITION, DELETION};
+
+use crate::display::format_relative_time_short;
use super::super::list::layout::{DiffDisplayConfig, DiffVariant};
@@ -84,9 +90,6 @@ pub(super) fn process_log_with_dimming(
log_output: &str,
unique_commits: Option<&HashSet<String>>,
) -> (String, Vec<String>) {
- use ansi_str::AnsiStr;
- use std::fmt::Write;
-
let dim = anstyle::Style::new().dimmed();
let reset = anstyle::Reset;
@@ -152,7 +155,6 @@ pub(super) fn format_log_output(
log_output: &str,
stats: &HashMap<String, (usize, usize)>,
) -> String {
- use crate::display::format_relative_time_short;
format_log_output_with_formatter(log_output, stats, format_relative_time_short)
}
@@ -167,9 +169,6 @@ pub(super) fn format_log_output_with_formatter<F>(
where
F: Fn(i64) -> String,
{
- use ansi_str::AnsiStr;
- use unicode_width::UnicodeWidthStr;
-
// First pass: find max display width of graph+hash prefix for alignment
let max_prefix_width = log_output
.lines()
@@ -247,10 +246,6 @@ pub(super) fn format_commit_line<F>(
where
F: Fn(i64) -> String,
{
- use ansi_str::AnsiStr;
- use unicode_width::UnicodeWidthStr;
- use worktrunk::styling::{ADDITION, DELETION};
-
let dim_style = anstyle::Style::new().dimmed();
let reset = anstyle::Reset;
diff --git a/src/commands/select/mod.rs b/src/commands/select/mod.rs
index 68d5e982e..980cbc2e8 100644
--- a/src/commands/select/mod.rs
+++ b/src/commands/select/mod.rs
@@ -7,9 +7,11 @@ mod log_formatter;
mod pager;
mod preview;
+use std::io::{IsTerminal, stderr};
use std::sync::Arc;
use anyhow::Context;
+use crossterm::{execute, terminal};
use skim::prelude::*;
use worktrunk::config::UserConfig;
use worktrunk::git::Repository;
@@ -26,8 +28,6 @@ pub fn handle_select(
show_remotes: bool,
config: &UserConfig,
) -> anyhow::Result<()> {
- use std::io::IsTerminal;
-
// Select requires an interactive terminal for the TUI
if !std::io::stdin().is_terminal() {
anyhow::bail!("wt select requires an interactive terminal");
@@ -223,8 +223,6 @@ pub fn handle_select(
// Clear the terminal screen after skim exits to prevent artifacts
// Use stderr for terminal control - stdout is reserved for data output
- use crossterm::{execute, terminal};
- use std::io::stderr;
execute!(stderr(), terminal::Clear(terminal::ClearType::All))?;
execute!(stderr(), crossterm::cursor::MoveTo(0, 0))?;
diff --git a/src/commands/select/pager.rs b/src/commands/select/pager.rs
index 3855e4138..903f4e259 100644
--- a/src/commands/select/pager.rs
+++ b/src/commands/select/pager.rs
@@ -2,6 +2,7 @@
//!
//! Handles detection and use of diff pagers (delta, bat, etc.) for preview windows.
+use std::io::Read;
use std::process::{Command, Stdio};
use std::sync::OnceLock;
use std::time::{Duration, Instant};
@@ -136,7 +137,6 @@ pub(super) fn run_git_diff_with_pager(git_args: &[&str], pager_cmd: &str) -> Opt
// Read output in a thread to avoid blocking
let stdout = child.stdout.take()?;
let reader_thread = std::thread::spawn(move || {
- use std::io::Read;
let mut stdout = stdout;
let mut output = Vec::new();
let _ = stdout.read_to_end(&mut output);
diff --git a/src/main.rs b/src/main.rs
index dcfdad03d..90bd8e423 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,9 +1,13 @@
+use std::collections::{HashMap, HashSet};
+use std::io::Write;
+
use anyhow::Context;
use clap::FromArgMatches;
-use color_print::cformat;
+use clap::error::ErrorKind as ClapErrorKind;
+use color_print::{ceprintln, cformat};
use std::process;
use worktrunk::config::{UserConfig, expand_template, set_config_path};
-use worktrunk::git::{Repository, exit_code, set_base_path};
+use worktrunk::git::{Repository, ResolvedWorktree, exit_code, set_base_path};
use worktrunk::path::format_path_for_display;
use worktrunk::shell::extract_filename_from_path;
use worktrunk::styling::{
@@ -11,6 +15,11 @@ use worktrunk::styling::{
warning_message,
};
+use commands::command_approval::approve_hooks;
+use commands::context::CommandEnv;
+use commands::list::progressive::RenderMode;
+use commands::worktree::RemoveResult;
+
mod cli;
mod commands;
mod completion;
@@ -37,8 +46,8 @@ use commands::command_executor::{CommandContext, build_hook_context};
use commands::handle_select;
use commands::worktree::{SwitchResult, handle_push};
use commands::{
- MergeOptions, OperationMode, RebaseResult, SquashResult, add_approvals, approve_hooks,
- clear_approvals, execute_switch, handle_completions, handle_config_create, handle_config_show,
+ MergeOptions, OperationMode, RebaseResult, SquashResult, add_approvals, clear_approvals,
+ execute_switch, handle_completions, handle_config_create, handle_config_show,
handle_configure_shell, handle_hints_clear, handle_hints_get, handle_hook_show, handle_init,
handle_list, handle_merge, handle_rebase, handle_remove, handle_remove_current,
handle_show_theme, handle_squash, handle_state_clear, handle_state_clear_all, handle_state_get,
@@ -59,12 +68,9 @@ use worktrunk::HookType;
/// For `wt switch` missing the branch argument, adds hints about shortcuts.
/// For unrecognized subcommands that match nested commands, suggests the full path.
fn enhance_and_exit_error(err: clap::Error) -> ! {
- use clap::error::ErrorKind;
- use color_print::ceprintln;
-
// For unrecognized subcommands, check if they match a nested subcommand
// e.g., `wt squash` -> suggest `wt step squash`
- if err.kind() == ErrorKind::InvalidSubcommand
+ if err.kind() == ClapErrorKind::InvalidSubcommand
&& let Some(unknown) = err.get(clap::error::ContextKind::InvalidSubcommand)
{
let cmd = cli::build_command();
@@ -82,7 +88,7 @@ fn enhance_and_exit_error(err: clap::Error) -> ! {
// Hints go to stderr, which is safe since stdout is reserved for data output.
// Check for both "wt switch" and "wt.exe switch" (Windows)
let err_str = format!("{err}");
- let is_switch_missing_arg = err.kind() == ErrorKind::MissingRequiredArgument
+ let is_switch_missing_arg = err.kind() == ClapErrorKind::MissingRequiredArgument
&& (err_str.contains("wt switch") || err_str.contains("wt.exe switch"));
if is_switch_missing_arg {
ceprintln!(
@@ -176,8 +182,6 @@ fn main() {
builder
.format(|buf, record| {
- use std::io::Write;
-
let msg = record.args().to_string();
// Map thread ID to a single character (a-z, then A-Z)
@@ -517,8 +521,6 @@ fn main() {
// "Approve at the Gate": approve pre-commit hooks upfront (unless --no-verify)
// Shadow verify: if user declines approval, skip hooks but continue squash
let verify = if verify {
- use commands::command_approval::approve_hooks;
- use commands::context::CommandEnv;
let env = CommandEnv::for_action("squash")?;
let ctx = env.context(yes);
let approved = approve_hooks(&ctx, &[HookType::PreCommit])?;
@@ -697,8 +699,6 @@ fn main() {
commands::statusline::run(claude_code)
}
None => {
- use commands::list::progressive::RenderMode;
-
// Load config and merge with CLI flags (CLI flags take precedence)
UserConfig::load()
.context("Failed to load config")
@@ -877,7 +877,7 @@ fn main() {
yes,
);
let template_vars = build_hook_context(&ctx, &extra_vars);
- let vars: std::collections::HashMap<&str, &str> = template_vars
+ let vars: HashMap<&str, &str> = template_vars
.iter()
.map(|(k, v)| (k.as_str(), v.as_str()))
.collect();
@@ -947,7 +947,6 @@ fn main() {
// Helper: approve remove hooks using current worktree context
// Returns true if hooks should run (user approved)
let approve_remove = |yes: bool| -> anyhow::Result<bool> {
- use commands::context::CommandEnv;
let env = CommandEnv::for_action_branchless()?;
let ctx = env.context(yes);
let approved = approve_hooks(
@@ -975,9 +974,6 @@ fn main() {
handle_remove_output(&result, background, run_hooks)
} else {
- use commands::worktree::RemoveResult;
- use worktrunk::git::ResolvedWorktree;
-
// Multi-worktree removal: validate ALL first, then approve, then execute
// This supports partial success - some may fail validation while others succeed.
let current_worktree = repo
@@ -988,7 +984,7 @@ fn main() {
// Dedupe inputs to avoid redundant planning/execution
let branches: Vec<_> = {
- let mut seen = std::collections::HashSet::new();
+ let mut seen = HashSet::new();
branches
.into_iter()
.filter(|b| seen.insert(b.clone()))
diff --git a/src/shell_exec.rs b/src/shell_exec.rs
index 17675ef29..4f7e1b017 100644
--- a/src/shell_exec.rs
+++ b/src/shell_exec.rs
@@ -8,11 +8,13 @@
//! On Windows, Git for Windows must be installed — this is nearly universal among
//! Windows developers since git itself is required.
+use std::io::{ErrorKind, Read, Write};
use std::path::PathBuf;
-use std::process::Command;
+use std::process::{Command, Stdio};
use std::sync::OnceLock;
use std::time::Instant;
+use crate::git::{GitError, WorktrunkError};
use crate::sync::Semaphore;
/// Semaphore to limit concurrent command execution.
@@ -253,9 +255,6 @@ fn run_with_timeout_impl(
cmd: &mut Command,
timeout: std::time::Duration,
) -> std::io::Result<std::process::Output> {
- use std::io::{ErrorKind, Read};
- use std::process::Stdio;
-
// Spawn process with piped stdout/stderr
let mut child = cmd
.stdin(Stdio::null())
@@ -523,9 +522,6 @@ impl Cmd {
/// Panics if called on a shell-wrapped command (created via `Cmd::shell()`).
/// Shell commands must use `.stream()` because they need TTY preservation.
pub fn run(self) -> std::io::Result<std::process::Output> {
- use std::io::Write;
- use std::process::Stdio;
-
assert!(
!self.shell_wrap,
"Cmd::shell() commands must use .stream(), not .run()"
@@ -668,8 +664,6 @@ impl Cmd {
///
/// Returns error if command exits with non-zero status.
pub fn stream(self) -> anyhow::Result<()> {
- use crate::git::{GitError, WorktrunkError};
- use std::io::Write;
#[cfg(unix)]
use {
signal_hook::consts::{SIGINT, SIGTERM},