Skip to main content

git_worktree_manager/operations/
exec.rs

1//! `gw exec <target> <cmd>` — single-worktree command dispatch.
2
3use std::io::Write;
4use std::path::Path;
5
6use crate::error::Result;
7use crate::git;
8use crate::operations::helpers::resolve_target_strict;
9
10pub fn exec_in_target<W: Write>(
11    cwd: &Path,
12    target: &str,
13    cmd: &[String],
14    out: &mut W,
15) -> Result<i32> {
16    let repo_root = git::get_main_repo_root(Some(cwd))?;
17    let resolved = resolve_target_strict(&repo_root, target)?;
18    let (s, code) = super::run::run_capture_one(&resolved.name, &resolved.path, cmd)?;
19    let _ = out.write_all(s.as_bytes());
20    Ok(code)
21}