Skip to content

Commit 6c3dade

Browse files
max-sixtyclaude
andauthored
fix(context): respect -C flag in CommandEnv worktree path (#899)
* Add OCR-based validation for TUI demos TUI demos (Zellij, interactive UIs) can't be validated via text snapshots because VHS only captures the outer terminal, not content inside multiplexers. Instead, extract key frames from GIFs and use OCR (tesseract) to verify expected patterns. Add `docs/demos/shared/validation.py` with checkpoint definitions and validation logic. Update build script to validate TUI demos with defined checkpoints during snapshot mode, skipping those without checkpoints. Document validation approach in CLAUDE.md with requirements and checkpoint definitions for wt-zellij-omnibus. * fix(demos): pre-populate Zellij permissions cache to avoid dialog The zellij-tab-name plugin shows a permission dialog on first run, which was appearing in recorded demos. Fix by pre-populating the permissions.kdl cache file before Zellij starts. Also simplifies the tape by removing the "y" keypress and clear that were working around the permission dialog. Co-Authored-By: Claude <noreply@anthropic.com> * fix(demos): re-enable OCR validation checkpoints, handle permission dialog race The permission dialog timing is non-deterministic (depends on macOS cache state). Handle both cases: - If dialog appears: "y" dismisses it - If no dialog (cache hit): "y" + Enter + clear cleans up the shell Re-enables validation checkpoints with calibrated frame numbers: - Frame 100: wt list output with branch table - Frame 500: Claude UI with Opus indicator - Frame 2000: Final wt list --full output Co-Authored-By: Claude <noreply@anthropic.com> * fix(context): respect `-C` flag in CommandEnv worktree path CommandEnv was using `std::env::current_dir()` instead of the path from the Repository, which meant it ignored the `-C` flag. This caused hooks to fail when running `wt -C /path/to/worktree hook ...` because CommandContext received the wrong worktree path. Changes: - Add `path()` accessor to WorkingTree for getting the stored path - Use `repo.current_worktree().path()` in for_action/for_action_branchless - Canonicalize paths in compute_hooks_display_path() for comparison (handles "." vs "/absolute/path" after the fix) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent c153164 commit 6c3dade

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

src/commands/context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl CommandEnv {
3030
/// Used in error messages when the environment can't be loaded.
3131
pub fn for_action(action: &str, config: UserConfig) -> anyhow::Result<Self> {
3232
let repo = Repository::current()?;
33-
let worktree_path = std::env::current_dir().context("Failed to get current directory")?;
33+
let worktree_path = repo.current_worktree().path().to_path_buf();
3434
let branch = repo.require_current_branch(action)?;
3535

3636
Ok(Self {
@@ -47,10 +47,10 @@ impl CommandEnv {
4747
/// such as running hooks (where `{{ branch }}` expands to "HEAD" if detached).
4848
pub fn for_action_branchless() -> anyhow::Result<Self> {
4949
let repo = Repository::current()?;
50-
let worktree_path = std::env::current_dir().context("Failed to get current directory")?;
50+
let current_wt = repo.current_worktree();
51+
let worktree_path = current_wt.path().to_path_buf();
5152
// Propagate git errors (broken repo, missing git) but allow None for detached HEAD
52-
let branch = repo
53-
.current_worktree()
53+
let branch = current_wt
5454
.branch()
5555
.context("Failed to determine current branch")?;
5656
let config = UserConfig::load().context("Failed to load config")?;

src/git/repository/working_tree.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ impl<'a> WorkingTree<'a> {
5757
self.repo
5858
}
5959

60+
/// Get the path this WorkingTree was created with.
61+
///
62+
/// This is the path passed to `worktree_at()` or `base_path()` for `current_worktree()`.
63+
/// For the canonical git-determined root, use [`root()`](Self::root) instead.
64+
pub fn path(&self) -> &Path {
65+
&self.path
66+
}
67+
6068
/// Run a git command in this worktree and return stdout.
6169
pub fn run_command(&self, args: &[&str]) -> anyhow::Result<String> {
6270
let output = self.run_command_output(args)?;

src/output/global.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,18 @@ pub fn compute_hooks_display_path<'a>(
251251
hooks_run_at: &'a std::path::Path,
252252
user_location: &std::path::Path,
253253
) -> Option<&'a std::path::Path> {
254-
if hooks_run_at == user_location {
254+
// Canonicalize both paths for comparison to handle relative vs absolute paths
255+
// (e.g., "." vs "/absolute/path/to/cwd"). Fall back to direct comparison if
256+
// canonicalization fails (e.g., path doesn't exist).
257+
let same_location = match (
258+
dunce::canonicalize(hooks_run_at),
259+
dunce::canonicalize(user_location),
260+
) {
261+
(Ok(h), Ok(u)) => h == u,
262+
_ => hooks_run_at == user_location,
263+
};
264+
265+
if same_location {
255266
None
256267
} else {
257268
Some(hooks_run_at)

0 commit comments

Comments
 (0)