Skip to content

Materialize stripped Git repository contents - #30321

Closed
tamird wants to merge 3 commits into
bazelbuild:masterfrom
tamird:tamird/fix-git-strip-prefix
Closed

tamird wants to merge 3 commits into
bazelbuild:masterfrom
tamird:tamird/fix-git-strip-prefix

Conversation

@tamird

@tamird tamird commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

git_repository keeps a complete checkout under .tmp_git_root and
symlinks the selected strip_prefix entries into the repository root.
Recursive package discovery can then see discarded sibling packages,
and traversal or an escaping directory symlink can expose data outside
the checkout.

Complete Git operations before stripping, reject paths that escape the
checkout or resolve into Git metadata, and move only the selected
subtree into place. Remove discarded entries and .git, preserve
add_prefix and patch behavior, and cover recursive queries, collisions,
and escape cases.

Fixes #26628.

— Description updated by Codex, on Tamir’s behalf.

@tamird
tamird marked this pull request as ready for review July 17, 2026 01:14
@github-actions github-actions Bot added the awaiting-review PR is awaiting review from an assigned reviewer label Jul 17, 2026
@iancha1992 iancha1992 added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website and removed team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. labels Jul 21, 2026
@tamird
tamird force-pushed the tamird/fix-git-strip-prefix branch from f00805a to a125189 Compare July 29, 2026 11:36
@tamird
tamird force-pushed the tamird/fix-git-strip-prefix branch from a125189 to 42e7be7 Compare July 29, 2026 19:16
@tamird
tamird force-pushed the tamird/fix-git-strip-prefix branch from 42e7be7 to ad9a536 Compare August 21, 2026 15:10
@bazel-docs-pr-commenter

Copy link
Copy Markdown

❌ Bazel docs preview deployment failed (Mintlify result: timed_out).

Please check the GitHub Actions logs for details.

Updated for ad9a536eb3cb8f2683c3cc50ae556cec325e4123

tamird added 2 commits August 27, 2026 22:59
git_repository keeps a complete checkout under .tmp_git_root and
symlinks the selected strip_prefix entries into the repository root.
Recursive package discovery can then see discarded sibling packages,
and traversal or an escaping directory symlink can expose data outside
the checkout.

Complete Git operations before stripping, reject paths that escape the
checkout or resolve into Git metadata, and move only the selected
subtree into place. Remove discarded entries and .git, preserve
add_prefix and patch behavior, and cover recursive queries, collisions,
and escape cases.

Fixes bazelbuild#26628.
macOS can use case-sensitive volumes, where .GIT/OBJECTS does not
name the metadata directory created by Git. Selecting that spelling
based on the OS makes the metadata-rejection check fail earlier with
a missing-directory error.

Use the uppercase spelling only when the fixture filesystem accepts
it, retaining lowercase metadata coverage on case-sensitive volumes.
@tamird

tamird commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

@meteorcloudy could you review this strip-prefix follow-up to #30309, which you reviewed and has now landed? It fixes discarded packages appearing in recursive discovery (#26628).

— Codex, on Tamir’s behalf.

@tamird
tamird force-pushed the tamird/fix-git-strip-prefix branch from ad9a536 to 69d2a0e Compare August 28, 2026 03:01
@kotlaja

kotlaja commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Looks good to me, thanks for fixing! :)

I have one question - On very large repos deleting the discarded tree during strip_prefix could add some I/O overhead, right?
If so, it might be worth recommending sparse_checkout_patterns to combine with strip_prefix for users to keep fetches fast.

Maybe adding something like this in the relevant doc:

"For large repositories, consider combining with sparse_checkout_patterns to avoid checking out and deleting unused files."

@kotlaja
kotlaja self-requested a review September 8, 2026 09:55
strip_prefix removes unused checkout contents after Git has
materialized them. Point users of large repositories to
sparse_checkout_patterns to limit that work, and clarify that the
patterns match paths in the original Git repository.
@tamird

tamird commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

@kotlaja

On very large repos deleting the discarded tree during strip_prefix could add some I/O overhead, right?

Yes. Added the sparse_checkout_patterns recommendation to the strip_prefix docs in e4df189. The note also clarifies that patterns match paths in the original Git repository, before stripping.

The generated Git-rule docs build and formatting check pass.

— Codex, on Tamir’s behalf.

@kotlaja

kotlaja commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Thanks! :)

@kotlaja kotlaja added awaiting-PR-merge copybara:import Trigger copybara to import the PR and removed awaiting-review PR is awaiting review from an assigned reviewer awaiting-PR-merge labels Sep 9, 2026
@copybara-service copybara-service Bot closed this in d4e306a Sep 9, 2026
@tamird
tamird deleted the tamird/fix-git-strip-prefix branch September 9, 2026 14:39
@kwvg

kwvg commented Oct 31, 2026

Copy link
Copy Markdown

@bazel-io flag

@bazel-io bazel-io added the potential release blocker Flagged by community members using "@bazel-io flag". Should be added to a release blocker milestone label Oct 31, 2026
@kwvg

kwvg commented Oct 31, 2026

Copy link
Copy Markdown

Requesting backport of this fix to Bazel 9.3 (tagging #32219), current Bazel 9.x behaviour breaks when importing Git revisions as Rust dependencies (example) as git_repository marks (triggered by crate_universe) them as reproducible and we enabled the remote repository cache in base-sdk#96 which broke builds after we merged the changes in and the cache got populated (source).

Build cited uses Bazel 9.1, reproduced locally with Bazel 9.2.

@kwvg kwvg mentioned this pull request Oct 31, 2026
5 tasks done
@iancha1992

Copy link
Copy Markdown
Contributor

@bazel-io fork 9.3.2

@iancha1992

Copy link
Copy Markdown
Contributor

@bazel-io fork 9.4.0

@bazel-io bazel-io removed the potential release blocker Flagged by community members using "@bazel-io flag". Should be added to a release blocker milestone label Nov 1, 2026
deepalak56 added a commit to deepalak56/bazel_deepa that referenced this pull request Dec 4, 2026
… (bazelbuild#33054)

git_repository keeps a complete checkout under .tmp_git_root and
symlinks the selected strip_prefix entries into the repository root.
Recursive package discovery can then see discarded sibling packages,
and traversal or an escaping directory symlink can expose data outside
the checkout.

Complete Git operations before stripping, reject paths that escape the
checkout or resolve into Git metadata, and move only the selected
subtree into place. Remove discarded entries and .git, preserve
add_prefix and patch behavior, and cover recursive queries, collisions,
and escape cases.

Fixes bazelbuild#26628.

— Description updated by Codex, on Tamir’s behalf.

---------

Co-authored-by: Will Stranton <[email protected]>
Co-authored-by: Tamir Duberstein <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

copybara:import Trigger copybara to import the PR team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Building git_override module with strip_prefix finds too many files

5 participants