Skip to content

Conversation

AgentEnder
Copy link
Member

Current Behavior

When an Nx workspace exists inside a subdirectory of another git repository or when parent directories contain .gitignore files, those ignore patterns can affect file traversal within the Nx workspace, making project resolution non-deterministic.

For example, if a workspace is inside a directory with * in its .gitignore, Nx fails to properly traverse workspace files.

Expected Behavior

Nx should respect .gitignore files in a smart way:

  • Workspace is git root: Ignores all parent gitignore files
  • Workspace nested in git repo: Respects gitignore files within the git repository but ignores any gitignore files above the git root
  • No git repo found: Respects all parent gitignore files (backwards compatibility)

This ensures deterministic project resolution regardless of where the workspace is located.

Related Issue(s)

Fixes #27368, #28000, #27295, #28123, #29413

Supersedes #29245 (incorporates feedback from @Cammisuli and @adamalton)

Implementation Details

The fix implements smart gitignore boundary detection that:

  1. Finds the nearest git repository root by walking up the directory tree
  2. Uses built-in git ignore handling for maximum compatibility
  3. Disables automatic parent discovery and manually adds only relevant .gitignore files
  4. Stops at git repository boundaries to prevent external gitignore files from affecting the workspace

This approach addresses the feedback from the original PR #29245 to handle both:

  • Standalone workspaces (where workspace root = git root)
  • Workspaces nested within larger git repositories

The solution leverages the ignore crate's existing functionality while providing precise control over which ignore files are considered.

Test Plan

  • Unit tests covering all three scenarios
  • Workspace is git root: ignores parent gitignores
  • Workspace nested in git repo: respects repo gitignores, ignores external ones
  • No git repo: uses all parent gitignores (backwards compatibility)
  • All existing walker tests continue to pass

🤖 Generated with Claude Code

Implements smart gitignore boundary detection that respects parent gitignore
files only up to the nearest git repository root, preventing external gitignore
files (e.g., in home directory) from affecting workspace traversal.

**Behavior:**
- **Workspace is git root**: Ignores all parent gitignore files
- **Workspace nested in git repo**: Respects gitignore files within the git
  repository but ignores any gitignore files above the git root
- **No git repo found**: Respects all parent gitignore files (backwards compatibility)

This resolves issues where workspaces would have missing projects or files
when parent directories contained overly broad gitignore patterns like "*".
The solution addresses feedback from PR #29245 to handle both standalone
workspaces and workspaces nested within larger git repositories.

Fixes #27368, #28000, #27295, #28123, #29413

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@AgentEnder AgentEnder requested review from a team as code owners July 14, 2025 15:24
Copy link

vercel bot commented Jul 14, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
nx-dev ✅ Ready (Inspect) Visit Preview Jul 14, 2025 3:37pm
Copy link
Contributor

nx-cloud bot commented Jul 14, 2025

View your CI Pipeline Execution ↗ for commit 0a430ed

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 8m 57s View ↗
nx run-many -t check-imports check-commit check... ✅ Succeeded 15s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 3s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 3s View ↗
nx documentation ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2025-07-14 17:20:05 UTC

@FrozenPandaz FrozenPandaz merged commit d207a5c into master Jul 17, 2025
7 of 8 checks passed
@FrozenPandaz FrozenPandaz deleted the fix-parent-gitignore branch July 17, 2025 16:13
Copy link
Contributor

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

2 participants