Repository navigation
Match .gitignore specs relative to walk root in walk_with_gitignore - #210
Merged
Merged
Conversation
walk_with_gitignore matched .gitignore specs against each file's absolute path. Git evaluates patterns relative to the repository root, so a root-anchored pattern (e.g. `/local`) matched the leading segment of an absolute checkout path such as `/local/home/<user>/aws-doc-sdk-examples` and silently excluded every file beneath the walk root. For WRITEME this meant a service's entire `src/` tree was dropped from the file walk on any `/local/...` checkout (the Cloud Desktop default), so every snippet beneath it reported as missing on every run, regardless of the author's change. Thread the top-level walk root through the recursion as `base` and match each path relative to it, mirroring git. Root-anchored patterns continue to work relative to the walk root (verified: `/build` ignores top-level build/ but keeps nested src/build/). A repo-side workaround for the specific `/local` collision was shipped in aws-doc-sdk-examples PR #8213; this fixes the underlying tool bug and prevents the whole class of issue.
mgrohols
approved these changes
Oct 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
walk_with_gitignore(inaws_doc_sdk_examples_tools/file_utils.py) matches.gitignorespecs against each file's absolute path. Git evaluates.gitignorepatterns relative to the repository root, so a root-anchored pattern (e.g./local,/home,/tmp) matches the leading segment of the checkout's absolute path. On a checkout under/local/home/<user>/aws-doc-sdk-examples(the default on many internal Cloud Desktops), a/localentry in any.gitignorematches/local/...and silently excludes the entire subtree from the walk.Real-world instance
In
awsdocs/aws-doc-sdk-examples,kotlin/services/bedrock/.gitignorewas copied verbatim from the upstream JetBrains Kotlin compiler repo and contained a root-anchored/localpattern. On a/local/...checkout this dropped all ofkotlin/services/bedrock/srcfrom the WRITEME file walk, so every snippet beneathsrc/reported as missing on every run:That was patched repo-side by replacing the stray
.gitignorein awsdocs/aws-doc-sdk-examples#8213, but that only addresses one file. This PR fixes the underlying tool bug so the whole class of root-anchored-pattern collisions can't recur, for any.gitignorein any consuming repo.(The symptom does not appear on GitHub-hosted CI, whose runner paths are
/home/runner/work/...and never match/local; it only manifests on local/local/...checkouts.)Fix
Thread the top-level walk root through the recursion as
baseand match each path relative to it, mirroring git's semantics. Root-anchored patterns still work correctly relative to the walk root (a/buildpattern ignores top-levelbuild/but keeps a nestedsrc/build/).Tests
Added two regression tests to
file_utils_test.py:test_root_anchored_pattern_does_not_match_checkout_prefix— reproduces the/localcollision; fails on the old code, passes with the fix.test_root_anchored_pattern_still_ignores_matching_dir— confirms root-anchored patterns are still honored relative to the walk root (not merely disabled).All 110 tests pass (
python3 -m pytest).Verified on a real
/localcheckoutBeyond the mocked unit tests, I exercised the fix against a real on-disk
aws-doc-sdk-examplescheckout under/local/...(the condition that triggers the bug), through the real snippet-scanning code path (collect_snippets->get_files->walk_with_gitignore):walk_with_gitignoreon an on-disk tree with a root-anchored/localpattern: the fixed code yields the Kotlin source file and still ignoresbuild/; the pre-fix absolute-matching logic dropped the entire tree.collect_snippetson the actual repo, with/localtemporarily injected intokotlin/services/bedrock/.gitignore: fixed code findsbedrock.kotlin.list_foundation_models.main; pre-fix absolute-matching does not find it — exactly the [Kotlin] Replace JetBrains boilerplate in bedrock .gitignore aws-doc-sdk-examples#8213 symptom.writeme.py --checkfor Kotlin bedrock (no/local): passes with no missing-snippet / DocGen errors.The injected
.gitignoreedit was temporary and restored to its clean tracked state after each test.Related