YoannAbriel opened a new pull request, #62860:
URL: https://github.com/apache/airflow/pull/62860

   ## Problem
   
   When using `.airflowignore` with negation patterns to selectively un-ignore 
deeply nested directories, directory-only patterns (ending with `/`) 
incorrectly un-ignore files inside those directories. 
   
   For example, with this `.airflowignore`:
   ```
   *
   !abc/
   !abc/def/
   !abc/def/xyz/
   !abc/def/xyz/*
   ```
   
   Files in `abc/` and `abc/def/` are incorrectly discovered, when only files 
in `abc/def/xyz/` should be.
   
   ## Root Cause
   
   `_GlobIgnoreRule.match()` passes file paths to 
`GitWildMatchPattern.match_file()` without distinguishing between 
directory-only patterns and general patterns. The `GitWildMatchPattern` treats 
a pattern like `abc/def/` as matching everything under `abc/def/` (including 
files), but per the [gitignore 
specification](https://git-scm.com/docs/gitignore):
   
   > If there is a separator at the end of the pattern then the pattern will 
only match directories, otherwise the pattern can match both files and 
directories.
   
   So `!abc/def/` should only un-ignore the *directory* `abc/def` (allowing 
traversal), not files within it.
   
   ## Fix
   
   - Added a `dir_only` flag to `_GlobIgnoreRule` that is set when the pattern 
(after stripping `!` prefix) ends with `/`.
   - In `_GlobIgnoreRule.match()`, directory-only rules are skipped when 
matching non-directory paths, ensuring they only affect directory traversal 
decisions.
   - Added a regression test reproducing the exact scenario from the issue.
   
   All 6 existing + new tests pass.
   
   Closes: #62716
   
   ##### Was generative AI tooling used to co-author this PR?
   - [X] Yes — Claude Code
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to