Skip to content

fix: resolve git root for init paths and fix Windows test compat (GIT-108)#74

Merged
TonyCasey merged 2 commits intomainfrom
GIT-108
Feb 15, 2026
Merged

fix: resolve git root for init paths and fix Windows test compat (GIT-108)#74
TonyCasey merged 2 commits intomainfrom
GIT-108

Conversation

@TonyCasey
Copy link
Copy Markdown
Owner

@TonyCasey TonyCasey commented Feb 15, 2026

Summary

  • Init commands (init, init-hooks) now use git rev-parse --show-toplevel instead of process.cwd() to resolve the repo root, preventing files from being written to the wrong directory when the shell cwd differs (e.g. JetBrains spawning a new terminal)
  • All git rev-parse --show-toplevel calls across the codebase now normalize paths with path.resolve() for cross-platform compatibility (Windows/macOS)
  • Fixed hook integration test helpers to use .cmd wrapper and shell: true on Windows
  • Fixed MCP integration test helpers to add shell: true on Windows for .cmd spawning
  • Fixed MCP test cleanup to handle Windows EPERM errors from lingering process file locks
  • Fixed unit test path assertions to use path.join() instead of hardcoded Unix separators

Test plan

  • 476 unit tests pass
  • 91 integration tests pass (previously ~50 were failing on Windows)
  • Build succeeds with no type errors

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added extraction workflow control and a configurable commit count for initialization.
  • Bug Fixes

    • Centralized Git root detection for more reliable, absolute path resolution.
    • Improved Windows compatibility for CLI/hooks execution and repository cleanup.
  • Tests

    • Updated tests for cross-platform path handling and Windows-friendly behavior.

…-108)

Init commands used process.cwd() which fails when the shell cwd differs
from the repo root (e.g. JetBrains spawning a new terminal). Now uses
git rev-parse --show-toplevel with path.resolve() for cross-platform
normalization. Also fixes integration test helpers to use .cmd wrappers
and shell:true on Windows for child process spawning.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
AI-Agent: Claude-Code/2.1.42
Copilot AI review requested due to automatic review settings February 15, 2026 19:59
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 15, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

Replaces inline git-root detection with a new resolver (resolveGitRoot), updates functions to accept/propagate a cwd for repository-aware path resolution, extends init command options, and adds Windows-friendly test helpers and cross-platform path assertions.

Changes

Cohort / File(s) Summary
Git root resolver & usage
src/infrastructure/git/resolveGitRoot.ts, src/commands/hook.ts, src/infrastructure/logging/factory.ts
Added getGitRoot/resolveGitRoot helper. Replaced in-file exec/git logic with imports of resolver; callers use resolved root instead of local exec fallback.
Init & init-hooks command updates
src/commands/init.ts, src/commands/init-hooks.ts
Init command now uses resolveGitRoot() for project root; IInitCommandOptions gained extract and commitCount; getSettingsPath(scope, cwd?) signature added and called with resolved cwd.
Tests — Windows compatibility & path portability
tests/integration/hooks/helpers.ts, tests/integration/mcp/helpers.ts, tests/unit/hooks/utils/config.test.ts
Spawn calls use shell: process.platform === 'win32' and select tsx.cmd on Windows; repo cleanup adds retry/EPERM tolerance; unit tests use path.join() for cross-platform assertions.

Sequence Diagram

sequenceDiagram
    participant Cmd as Command
    participant Resolver as resolveGitRoot
    participant FS as Path.resolve
    participant Settings as getSettingsPath

    rect rgba(76, 175, 80, 0.5)
    Cmd->>Resolver: request git root (cwd?)
    Resolver->>Resolver: exec git rev-parse --show-toplevel
    alt git root found
        Resolver-->>Cmd: git root path
    else not a git repo
        Resolver-->>Cmd: fallback to process.cwd()
    end
    Cmd->>FS: resolve(path)
    FS-->>Cmd: absolute cwd
    Cmd->>Settings: getSettingsPath(scope, cwd)
    Settings-->>Cmd: settings path (repo-aware)
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: git root resolution for init paths and Windows test compatibility fixes.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch GIT-108

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

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes cross-platform compatibility issues related to git root resolution and Windows test execution. The changes ensure that init commands use the git repository root instead of the current working directory, and that all tests can run successfully on Windows.

Changes:

  • Init commands now resolve git root using git rev-parse --show-toplevel instead of process.cwd()
  • All git root resolution calls normalized with path.resolve() for Windows compatibility
  • Test helpers updated to use .cmd wrappers and shell: true on Windows for proper executable spawning

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/unit/hooks/utils/config.test.ts Updated path assertions to use path.join() for cross-platform compatibility
tests/integration/mcp/helpers.ts Added .cmd wrapper for tsx on Windows, shell: true option, and enhanced cleanup with retry logic
tests/integration/hooks/helpers.ts Added .cmd wrapper for tsx on Windows and shell: true option for spawn calls
src/infrastructure/logging/factory.ts Added path.resolve() normalization to git root resolution
src/commands/init.ts Added resolveGitRoot() function and updated to use git root instead of process.cwd()
src/commands/init-hooks.ts Added resolveGitRoot() function and updated getSettingsPath() to accept optional cwd parameter
src/commands/hook.ts Added path.resolve() normalization to findGitRoot() function

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/commands/init.ts Outdated
Comment thread tests/integration/mcp/helpers.ts Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@src/commands/init-hooks.ts`:
- Around line 20-34: The function resolveGitRoot (used in
src/commands/init-hooks.ts) is duplicated as resolveGitRoot/findGitRoot in other
modules; extract this logic into a single shared utility function (e.g., export
a new getGitRoot or resolveGitRoot from a new module like
src/infrastructure/git/utils.ts or src/hooks/utils.ts), replace the duplicated
implementations in init-hooks.ts, init.ts and hook.ts to import and call the
shared function, and remove the duplicate local functions; ensure the new
utility preserves the same behavior (execFileSync with 'git rev-parse
--show-toplevel' and fallback to process.cwd()) and update any imports/exports
accordingly.

In `@tests/integration/mcp/helpers.ts`:
- Around line 197-204: The cleanupRepo function currently swallows all errors
from rmSync; change the error handling so that you only ignore EPERM on Windows
and rethrow any other errors. In the catch block for cleanupRepo, inspect the
caught error (from rmSync) and if the platform is Windows (process.platform ===
'win32') and the error code is 'EPERM' then silently return, otherwise rethrow
the error so failures on macOS/Linux surface; reference the cleanupRepo function
and the rmSync call and check error.code === 'EPERM' plus process.platform for
the platform branch.

Comment thread src/commands/init-hooks.ts Outdated
Comment thread tests/integration/mcp/helpers.ts
…catch (GIT-108)

Addresses review feedback: deduplicate resolveGitRoot/getGitRoot into
src/infrastructure/git/resolveGitRoot.ts shared by init, init-hooks,
hook, and logging factory. Scope MCP cleanup catch to only suppress
EPERM on Windows, rethrowing other errors on macOS/Linux.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
AI-Agent: Claude-Code/2.1.42
@TonyCasey TonyCasey merged commit 7357675 into main Feb 15, 2026
3 checks passed
@TonyCasey TonyCasey deleted the GIT-108 branch February 15, 2026 21: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.

2 participants