Skip to content

Conversation

@fbosch
Copy link
Owner

@fbosch fbosch commented Feb 5, 2026

Summary

Expand brace syntax patterns like **/*.{md,mdx,txt} for git sparse-checkout compatibility.

Changes

  • Add expandBracePattern() to convert brace patterns to individual extensions
  • Refactor normalizeSparsePatterns() to call expansion during normalization
  • Add comprehensive test coverage for brace expansion with mocked git
  • Test default pattern expansion when no include specified

Summary by CodeRabbit

  • New Features
    • Brace pattern expansion for sparse-checkout so patterns like **/*.{md,mdx,txt} are expanded automatically for precise file selection.
  • Tests
    • Added integration tests validating brace expansion, default-include behavior, and that sparse-checkout is invoked with expanded patterns.
  • Documentation
    • README updated to describe brace expansion behavior, limits, and supported patterns.
  • Chores
    • Hardened Git environment/command handling, CI workflow updates, .gitignore changes, and new guidance in AGENTS.md.

Copilot AI review requested due to automatic review settings February 5, 2026 14:45
@coderabbitai
Copy link

coderabbitai bot commented Feb 5, 2026

📝 Walkthrough

Walkthrough

Replace in-file Git env construction with exported buildGitEnv and resolveGitCommand; add brace-style sparse-checkout expansion with MAX_BRACE_EXPANSIONS and expandBracePattern; update sparse pattern normalization and git invocations; add integration tests and small docs/.gitignore edits.

Changes

Cohort / File(s) Summary
Git env & git invocations
src/git/git-env.ts, src/git/resolve-remote.ts, src/git/fetch-source.ts
Add exported buildGitEnv() and resolveGitCommand(); use buildGitEnv() for git subprocess env and resolveGitCommand() when invoking git; replace local env builder with imports.
Sparse pattern & brace expansion
src/git/fetch-source.ts
Introduce MAX_BRACE_EXPANSIONS, expandBracePattern(pattern), and update normalizeSparsePatterns() to expand {a,b}-style braces into multiple sparse-checkout entries; downstream sparse-checkout setup now consumes expanded patterns.
Tests (integration & shim)
tests/integration-real-repos.test.js, tests/sparse-brace-expansion.test.js
Add test for default include behavior; add integration tests using a git shim to assert sparse-checkout receives brace-expanded patterns for explicit and default include cases.
Gitignore & docs
.gitignore, README.md
Add general *.md ignore with exceptions for AGENTS.md and README.md; document brace expansion behavior, limits (max expansions), and unsupported nested braces/ranges in README.
CI workflow
.github/workflows/ci.yml
Change CI to run a Node 18 build job and a dependent matrix job for Node 20/22 across OSes (restructured steps and fail-fast settings).
Agent guidance
AGENTS.md
Add “Git workflow” guidance and updated testing guidance about extending tests under tests/ rather than adding new files by default.

Sequence Diagram(s)

(Skipped — changes are algorithmic and localized; no new multi-component sequential flow requiring visualization.)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 I nibble at braces, split them neat,
Patterns hop out in a tidy fleet,
Git finds its path, env snug and bright,
Sparse-checkout sprouts in morning light,
Tests thump happy paws in delight.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(sparse): support brace patterns in includes' accurately describes the main change: adding brace expansion support for sparse-checkout include patterns.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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 fix/default-includes

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 and usage tips.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 5, 2026

Open in StackBlitz

npx https://pkg.pr.new/fbosch/docs-cache@25

commit: 79929a6

Copy link
Contributor

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 pull request adds support for brace pattern expansion in sparse-checkout include patterns, specifically for file extension patterns like **/*.{md,mdx,txt}. Before this change, such patterns would be passed directly to git sparse-checkout, which doesn't support brace expansion natively. The implementation expands these patterns into individual patterns (e.g., **/*.md, **/*.mdx, **/*.txt) before passing them to git.

Changes:

  • Added expandBracePattern() function to expand simple brace patterns in file extension globs
  • Modified normalizeSparsePatterns() to apply brace expansion to all patterns
  • Added comprehensive tests for brace expansion in sparse-checkout scenarios
  • Added integration test to verify default patterns work with real repositories

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 12 comments.

File Description
src/git/fetch-source.ts Implements brace pattern expansion for file extensions in sparse-checkout patterns
tests/sparse-brace-expansion.test.js Adds unit tests for brace pattern expansion with mocked git commands
tests/integration-real-repos.test.js Adds integration test verifying default pattern works with actual repository

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

Copy link

@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 `@tests/sparse-brace-expansion.test.js`:
- Around line 165-267: The test "sync expands default brace pattern when no
include specified" duplicates setup/teardown and repeats the same git shim PATH
mutation that causes CI flakes; extract a shared helper (e.g.,
createTestContext) to perform tmp dir creation, mkdir for binDir and cachePath,
writeGitShim(binDir, logPath) and writeFile(logPath, ""), and another helper
(e.g., withModifiedPath) to set/unset
process.env.PATH/Path/PATHEXT/DOCS_CACHE_GIT_DIR around running runSync; replace
the duplicated inline setup/cleanup in this test (and the earlier test that
mirrors lines 62-109) to call createTestContext and wrap the run in
withModifiedPath so the git shim is always present and env is restored in
finally.
- Around line 61-163: The resolve-remote.ts code calls execFileAsync("git", ...)
without the modified PATH, so the git shim in tests isn't used; import or
otherwise share the buildGitEnv function used by fetch-source.ts and pass its
result as the env option to execFileAsync calls in resolveRemoteCommit (and any
other execFileAsync invocations in resolve-remote.ts) so the spawned git process
uses the test binDir PATH; alternatively extract buildGitEnv to a small shared
helper module and use that from both fetch-source.ts and resolve-remote.ts.
🧹 Nitpick comments (1)
tests/sparse-brace-expansion.test.js (1)

142-149: Assertion assumes fixed argument order after set.

The slice args.slice(patternIndex + 2) assumes --no-cone always immediately follows set. If the argument order changes (e.g., patterns before flags, or additional flags), this assertion could break silently.

Consider a more robust approach:

// Filter to just the pattern-like arguments
const patterns = args.slice(patternIndex + 1).filter(arg => !arg.startsWith("--"));

Copy link

@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/git/fetch-source.ts`:
- Around line 262-297: In expandBracePattern (and its inner expand function) the
MAX_BRACE_EXPANSIONS check happens after pushing to results, allowing an
off-by-one; before calling results.push(value) ensure you check if
results.length >= MAX_BRACE_EXPANSIONS and throw the same Error (using
MAX_BRACE_EXPANSIONS and pattern) so the limit is enforced strictly; apply this
pre-push check in both places where results.push(value) is used inside expand to
prevent exceeding the cap.

In `@src/git/git-env.ts`:
- Around line 24-25: Replace the invalid environment variable key
GIT_CONFIG_NOGLOBAL with the correct GIT_CONFIG_GLOBAL and set its value to
"/dev/null" in the git environment object (the entries containing
GIT_CONFIG_NOSYSTEM and GIT_CONFIG_NOGLOBAL); update the symbol
GIT_CONFIG_NOGLOBAL to GIT_CONFIG_GLOBAL and assign "/dev/null" so Git global
config is effectively disabled.
🧹 Nitpick comments (1)
src/git/git-env.ts (1)

6-22: Redundant re-assignments after spreading process.env.

Lines 10-22 explicitly re-assign variables that are already included via ...process.env on line 7. These assignments have no effect unless the intent is to document which variables are preserved. If documentation is the goal, consider adding a comment instead.

♻️ Simplified version (if explicit re-assignment isn't needed)
 return {
   ...process.env,
   ...(pathValue ? { PATH: pathValue, Path: pathValue } : {}),
   ...(pathExtValue ? { PATHEXT: pathExtValue } : {}),
-  HOME: process.env.HOME,
-  USER: process.env.USER,
-  USERPROFILE: process.env.USERPROFILE,
-  TMPDIR: process.env.TMPDIR,
-  TMP: process.env.TMP,
-  TEMP: process.env.TEMP,
-  SYSTEMROOT: process.env.SYSTEMROOT,
-  WINDIR: process.env.WINDIR,
-  SSH_AUTH_SOCK: process.env.SSH_AUTH_SOCK,
-  SSH_AGENT_PID: process.env.SSH_AGENT_PID,
-  HTTP_PROXY: process.env.HTTP_PROXY,
-  HTTPS_PROXY: process.env.HTTPS_PROXY,
-  NO_PROXY: process.env.NO_PROXY,
   GIT_TERMINAL_PROMPT: "0",
   GIT_CONFIG_NOSYSTEM: "1",
-  GIT_CONFIG_NOGLOBAL: "1",
+  GIT_CONFIG_GLOBAL: "",
   ...(process.platform === "win32" ? {} : { GIT_ASKPASS: "/bin/false" }),
 };

Windows child_process.execFile() doesn't always respect PATH when
resolving bare command names like 'git'. This caused tests to invoke
the real git.exe instead of the git.cmd shim.

Solution:
- Add resolveGitCommand() helper that checks DOCS_CACHE_GIT_COMMAND env var
- Export and use resolveGitCommand() in fetch-source.ts and resolve-remote.ts
- Set DOCS_CACHE_GIT_COMMAND to absolute path in test's withModifiedPath()
- Ensures Windows CI uses git.cmd shim instead of system git

Fixes sparse-brace-expansion.test.js on Windows CI.
Add comprehensive review guidelines for implementing PR feedback:
- Cross-platform testing requirements
- Code quality expectations
- Testing best practices (DOCS_CACHE_GIT_COMMAND override)
- Documentation requirements

These guidelines capture lessons learned from PR #25 feedback
implementation to help maintain code quality and consistency.
@fbosch fbosch merged commit 205d28f into master Feb 5, 2026
16 checks passed
@fbosch fbosch deleted the fix/default-includes branch February 5, 2026 17:04
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.

1 participant