Weihang Lo cf622c4be3
fix(vendor): recursively filter git files in subdirectories (#16439)
### What does this PR try to resolve?

Fixes #16148
Fixes #13607

Right now cargo vendor only filters .gitattributes, .gitignore, and .git
at the top level of each package. If these files exist in
subdirectories, they don't get filtered. This causes problems when the
vendored code gets checked into a git repo - git processes those files
and modifies them, which breaks checksums.

I ran into this when trying to vendor libssh2-sys. The .gitattributes
file in libgit2/src/util/ was getting its line endings changed by git,
causing checksum failures.

### How should we test and review this PR?

This follows the atomic commit pattern:
- First commit adds a test showing the current buggy behavior (test
passes)
- Second commit implements the fix and updates test assertions (test
still passes)

The fix uses components() to recursively check for .git directories
(since they can appear at any path level like deep/nested/.git/config),
while using file_name() for .gitattributes and .gitignore files.

### Additional context

This should also help with #13607 since it filters .gitignore and .git
recursively too.

If people actually need git functionality in their vendored deps, they
can add rules to their own .gitattributes at the root level.
2025-12-27 14:28:13 +00:00
..