Skip to content

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

docs(commands): name CommandEnv's two constructors after what actually differs (#3970)

Worktrunk Bot78552b700fe7
diff --git a/src/commands/context.rs b/src/commands/context.rs
index b45252bd6..7702e5701 100644
--- a/src/commands/context.rs
+++ b/src/commands/context.rs
@@ -75,11 +75,15 @@ impl CommandEnv {
})
}
- /// Load the command environment without requiring a branch.
+ /// Load the command environment, taking [`UserConfig`] from the repository's
+ /// own cached load rather than from the caller.
///
- /// Use this for commands that can operate in detached HEAD state,
- /// such as running hooks (where `{{ branch }}` expands to "HEAD" if detached).
- pub fn for_action_branchless() -> anyhow::Result<Self> {
+ /// The branch is resolved exactly as [`Self::for_action`] resolves it —
+ /// `None` in detached HEAD, and required only by a later
+ /// [`Self::require_branch`] call. The config source is the whole
+ /// difference: use this where the caller has no `UserConfig` in hand and
+ /// the repository has already loaded one.
+ pub fn for_action_loading_config() -> anyhow::Result<Self> {
let repo = Repository::current()?;
let current_wt = repo.current_worktree();
let worktree_path = current_wt.root()?;
diff --git a/src/commands/hook_commands.rs b/src/commands/hook_commands.rs
index 44ddfee5d..320e9eccd 100644
--- a/src/commands/hook_commands.rs
+++ b/src/commands/hook_commands.rs
@@ -205,8 +205,9 @@ pub fn run_hook(
shorthand_vars,
forwarded_args,
} = cli;
- // Derive context from current environment (branch-optional for CI compatibility)
- let env = CommandEnv::for_action_branchless()?;
+ // Derive context from the current environment; `config` isn't in hand here,
+ // so let the repository supply its cached load.
+ let env = CommandEnv::for_action_loading_config()?;
let repo = &env.repo;
let ctx = env.context(yes);
@@ -364,11 +365,11 @@ pub fn handle_hook_show(
.map(crate::cli::parse_hook_type)
.transpose()?;
- // Build context for template expansion (only used if --expanded)
- // Need to keep CommandEnv alive for the lifetime of ctx
- // Uses branchless mode - template expansion uses "HEAD" in detached HEAD state
+ // Build context for template expansion (only used if --expanded).
+ // Need to keep CommandEnv alive for the lifetime of ctx. Detached HEAD is
+ // fine: `{{ branch }}` expands to "HEAD" there.
let env = if expanded {
- Some(CommandEnv::for_action_branchless()?)
+ Some(CommandEnv::for_action_loading_config()?)
} else {
None
};