Skip to content

fix(core): build finds 0 pages when a folder above the docs matches a .gitignore pattern - #274

Merged
mgks merged 1 commit into
docmd-io:mainfrom
svallory:up-fix-gitignore-ancestors
Nov 11, 2026
Merged

mgks merged 1 commit into
docmd-io:mainfrom
svallory:up-fix-gitignore-ancestors

Conversation

@svallory

Copy link
Copy Markdown
Contributor

Description

A side fix found while working on #267 (not one of its numbered steps).

docmd build reports "Generated 0 pages" when the project folder, or any folder above it, has the same name as an unanchored .gitignore pattern. The usual way to hit it: the project is checked out at /srv/site (a common container path) and its .gitignore lists site/, the default output dir. Rename the folder and the same project builds every page.

Repro on main:

mkdir -p /tmp/repro/site/docs && cd /tmp/repro/site
echo '# Home' > docs/index.md
echo '{"title":"T","src":"docs","out":"site"}' > docmd.config.json
echo 'site/' > .gitignore
docmd build   # Generated 0 pages

Cause: in packages/core/src/engine/assets.ts, isExcludedPath checks unanchored patterns against the absolute path (normalizedPath.includes('/site/')), so /tmp/repro/site/docs/index.md matches site/. The .gitignore patterns from every directory up the tree are merged into one list and lose the directory they came from.

Fix:

  • Each .gitignore pattern keeps the directory of its .gitignore. The unanchored segment check and the wildcard check run against the path below that directory only, as git does.
  • config.exclude patterns are matched below the project directory (or the source dir, when it is outside the project directory).
  • Unchanged: exact-name, *.ext and prefix-* matches on the entry name, anchored (/x) patterns, and the built-in hidden names. A pattern in a parent repo's .gitignore still applies to everything below it.

commands/mcp.ts has its own copy of this matcher (isExcludedByPatterns, used by search_docs with config.exclude). I left it alone to keep this PR to the build; happy to switch it to the shared matcher in a follow-up if you want.

Type of change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📝 Documentation update

How it was verified

New tests/cli-contracts/gitignore-scope.test.js, registered as gitignore-scope in tests/runner.js:

  • a real docmd build in a folder named site with site/ and drafts/ gitignored (2 pages, drafts still ignored), and the same project under another folder name;
  • an ancestor named like a segment pattern (drafts/) and like a wildcard pattern (build-*/) does not hide the project, while docs/drafts/ and *.secret.md are still ignored;
  • a pattern in a parent directory's .gitignore still ignores what is below it;
  • exclude: ["drafts"] hides docs/drafts/ but not an ancestor folder named drafts.

Results:

  • On main, 4 of the 6 checks fail; with the fix all 6 pass.
  • node tests/runner.js --only=gitignore-scope,plugin-assets-pipeline,mcp-read-doc,features,validate-workspace: 235 passed, 0 failed. The existing .gitignore / exclude checks in plugin-assets-pipeline pass unchanged.
  • Mutation-tested: putting back the absolute-path segment check fails 3 checks; putting back the absolute-path wildcard check fails 1.
  • pnpm lint: no new warnings in the changed files.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (no documented behaviour changes)
  • My changes generate no new warnings

… their own directory

`docmd build` found 0 pages when the project folder (or any folder above
it) had the same name as an unanchored .gitignore pattern. The common
case: a checkout at /srv/site with `site/` (the default output dir) in
its .gitignore. The directory-segment and glob checks ran against the
absolute path, so `/srv/site/docs/index.md` matched `site/` and every
page was hidden.

- Each .gitignore pattern now carries the directory of the .gitignore it
  came from. Unanchored segment and wildcard checks run against the path
  below that directory only, as git does.
- `config.exclude` patterns are relative to the project directory (the
  scan root when the source dir is outside it).
- Exact-name, suffix and prefix matches on the entry name, and anchored
  (`/x`) patterns, are unchanged.
- A pattern in a parent repo's .gitignore still applies to what is below
  it.
- tests/cli-contracts/gitignore-scope.test.js, registered as
  `gitignore-scope`: a real build in a folder named `site`, ancestors
  named like a segment pattern and like a wildcard pattern, a parent
  .gitignore, and `exclude` with an ancestor of the same name.
@mgks

mgks commented Nov 11, 2026

Copy link
Copy Markdown
Member

Great catch on the ancestor .gitignore matching, Saulo!

Checking unanchored patterns against absolute paths was a silent trap, especially when deploying in container environments mapped to /srv/site. Scoping the pattern matching to the directory declaring the .gitignore aligns with native Git behavior and prevents the compiler from emitting '0 pages'.

Verified and passes all contract tests. Merging!

@mgks
mgks merged commit d399e3a into docmd-io:main Nov 11, 2026
1 check passed
mgks added a commit that referenced this pull request Nov 11, 2026
…ture additions

Synchronize working branch 'dev-0.9.10' with 'main' following the review,
security audit, and integration of 6 community pull requests alongside our
static asset root mirroring feature.

Merged Community Contributions:
- PR #271 (@GPT-AGI / Ting Zhang): fix(parser): resolve folder-index links from nested pages
  Fixes relative link resolution for non-index folder references from deep subdirectories.
- PR #274 (@svallory): fix(core): build finds 0 pages when an ancestor folder matches .gitignore
  Confines gitignore matching to repository root and avoids empty builds when parent paths match ignore patterns.
- PR #275 (@svallory): fix(build): keep git tree clean after pnpm -r run build
  Eliminates timestamps from generated plugin registry and ignores pre-built native binaries across architectures.
- PR #276 (@svallory): fix(tests): give each test run its own temp fixture root
  Isolates test fixtures into unique run directories under os.tmpdir() to prevent concurrency collisions.
- PR #272 (@svallory): feat(api,core): plugin actions receive caller context; one shared action host
  Introduces shared ActionHost with caller context (identity, mode, transport, headers without cookies), origin allowlisting, and unified rebuild queue.
- PR #273 (@svallory): feat(core): docmd serve, a production server for the built site
  Adds zero-dependency production HTTP/WS server with gzip compression, security headers (CSP, HSTS, CORS), health check endpoints (/healthz, /livez, /readyz), and SPA / clean URL routing.

Working Branch Features Included:
- feat(core): Zero-config static root asset mirroring
  Copies static assets from 'public/' or 'static/' (and docs/public/) directly to the output root ('site/'), preserving directory structure and files like 'funding.json', 'CNAME', and '.well-known/'. Adds canonical 'static' configuration option with support for boolean or custom directory lists.
- feat(cli): --host flag support for dev and serve commands (defaults to loopback 127.0.0.1 for CWE-1385 protection, configurable to 0.0.0.0 for container / LAN hosting).

Documentation Impact:
- Configuration Reference: Document 'static' setting (boolean | string[]).
- CLI Reference: Document 'docmd serve' command options and '--host' flag.
- Plugin Guide: Document ActionHost caller context and execution modes.
@mgks mgks mentioned this pull request Nov 13, 2026
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