Skip to content

Make hook execution working directory explicit - #202

Merged
errfld merged 2 commits into
mainfrom
gh-201/explicit-working-directory
Aug 10, 2026
Merged

Make hook execution working directory explicit#202
errfld merged 2 commits into
mainfrom
gh-201/explicit-working-directory

Conversation

@errfld

@errfld errfld commented Aug 10, 2026

Copy link
Copy Markdown
Owner

Summary

  • make hook command working-directory policy explicit at the executor runner boundary
  • add an additive summary executor API that accepts a working directory while preserving existing API behavior
  • resolve the repository root without changing the CLI process cwd and run configured commands from that root
  • cover nested directories, bare repositories, linked worktrees, and successful/failed caller-cwd preservation

TDD

RED was established with successful_run_preserves_callers_current_directory and failed_run_preserves_callers_current_directory: both failed because run_hook left the process cwd at the repository root (the second test also observed the poisoned test lock after the first assertion failure).

Validation

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo test -p git-smee-core executor
  • cargo test -p git-smee-core repository
  • cargo test -p git-smee-cli --test cli_integration (74 passed)
  • cargo test --workspace --all-targets --all-features

Fixes #201

Summary by CodeRabbit

  • Bug Fixes
    • Hooks now run from the repository root, including when triggered from nested directories.
    • Relative configuration paths are resolved consistently from the repository root.
    • Hook output files are created in the expected repository or worktree location.
    • The caller’s current directory remains unchanged after successful or failed hook execution.
    • Improved compatibility for hook execution paths on Windows.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@errfld, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 54 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: e918eed2-47b4-4a22-8770-10f3ef046224

📥 Commits

Reviewing files that changed from the base of the PR and between 9daa0cc and 78c9aec.

📒 Files selected for processing (3)
  • crates/git-smee-cli/src/commands/run.rs
  • crates/git-smee-core/src/executor.rs
  • crates/git-smee-core/src/executor/runner.rs
📝 Walkthrough

Walkthrough

Hook execution now uses an explicit repository working directory. The CLI no longer changes the caller’s current directory. Executor and runner APIs support explicit directories, with tests for nested directories, bare repositories, linked worktrees, and failed execution.

Changes

Hook working-directory execution

Layer / File(s) Summary
Runner working-directory policy
crates/git-smee-core/src/executor/runner.rs
PlatformCommandRunner now supports inherited or explicit working directories and applies platform-compatible paths when spawning commands.
Directory-aware executor API
crates/git-smee-core/src/executor.rs
The executor keeps inherited-directory behavior and adds execute_hook_with_summary_in_directory for explicit hook directories. Tests verify child output in the requested directory.
CLI root resolution and integration coverage
crates/git-smee-cli/src/commands/run.rs, crates/git-smee-cli/tests/cli_integration.rs
run_hook resolves the repository root without changing process state. Tests cover nested directories, bare repositories, linked worktrees, and successful or failed execution.


Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

Sequence Diagram(s)

sequenceDiagram
  participant CLI_run_hook
  participant Git_repository
  participant Executor
  participant PlatformCommandRunner
  participant Hook_command

  CLI_run_hook->>Git_repository: find repository root
  CLI_run_hook->>Executor: execute hook with root directory
  Executor->>PlatformCommandRunner: configure explicit working directory
  PlatformCommandRunner->>Hook_command: spawn command at repository root
  Hook_command-->>CLI_run_hook: execution result
Loading

Poem

A rabbit hops from nested ground,
While hooks run where roots are found.
No caller path is moved or spun,
Bare and linked worktrees join the fun.
Explicit paths guide each command,
Tests leave markers where they stand.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: making hook execution working-directory handling explicit.
Linked Issues check ✅ Passed The changes satisfy issue #201 by passing an explicit repository root, preserving APIs, avoiding CLI cwd mutation, and adding required tests.
Out of Scope Changes check ✅ Passed The changes remain focused on hook execution, repository-root resolution, executor behavior, and related tests; no unrelated migration work is included.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch gh-201/explicit-working-directory

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/git-smee-core/src/executor/runner.rs`:
- Around line 207-215: Update the Windows-only cmd_compatible_path function to
handle paths beginning with \\?\UNC\ by converting them to the absolute UNC form
\\server\share\repo before returning. Preserve the existing \\?\ drive-letter
prefix removal behavior for non-UNC paths, ensuring the result remains suitable
for shell_command.current_dir().
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: dd2afad9-46e7-4ed5-904c-ae7ab2e5eab5

📥 Commits

Reviewing files that changed from the base of the PR and between a8a6327 and 9daa0cc.

📒 Files selected for processing (4)
  • crates/git-smee-cli/src/commands/run.rs
  • crates/git-smee-cli/tests/cli_integration.rs
  • crates/git-smee-core/src/executor.rs
  • crates/git-smee-core/src/executor/runner.rs

Comment thread crates/git-smee-core/src/executor/runner.rs
@errfld
errfld merged commit 3c2fd0f into main Aug 10, 2026
28 checks passed
@errfld
errfld deleted the gh-201/explicit-working-directory branch August 10, 2026 06:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make hook execution working directory an explicit input

2 participants