Skip to content

[9.4.0] Materialize stripped Git repository contents (#30321) - #33054

Merged
meteorcloudy merged 3 commits into
bazelbuild:release-9.4.0from
deepalak56:cp30321-940-v2
Dec 2, 2026
Merged

meteorcloudy merged 3 commits into
bazelbuild:release-9.4.0from
deepalak56:cp30321-940-v2

Conversation

@deepalak56

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.

willstranton and others added 2 commits December 1, 2026 13:09
Similar to `http_archive`'s `add_prefix` attribute, this allows git repos to be cloned into a given subdirectory.

Fixes bazelbuild#25453

See bazelbuild#25453 . This also further aligns the attributes of `http_archive` with `git_repository`

> 1. Has this been discussed in a design doc or issue? (Please link it)

See bazelbuild#25453

> 2. Is the change backward compatible?

Yes - an attribute is added.  It is optional to use.

> 3. If it's a breaking change, what is the migration plan?

N/A

- [X] I have added tests for the new use cases (if any).
- [X] I have updated the documentation (if applicable).

RELNOTES[NEW]: Add `add_prefix` attribute to `git_repository` to allow cloning repositories into a given subdirectory prefix

Closes bazelbuild#29453.

PiperOrigin-RevId: 910704876
Change-Id: I3a916322254c5e6c91d82f000d084c6fc4fc8331
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.

Closes bazelbuild#30321

COPYBARA_INTEGRATE_REVIEW=bazelbuild#30321 from tamird:tamird/fix-git-strip-prefix e4df189
PiperOrigin-RevId: 978535521
Change-Id: I6937876c24f417901bcce9f42a0600fe391b0651
@deepalak56
deepalak56 requested a review from a team as a code owner December 1, 2026 13:17
@deepalak56 deepalak56 added team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website awaiting-review PR is awaiting review from an assigned reviewer labels Dec 1, 2026
@deepalak56
deepalak56 requested a review from kotlaja December 1, 2026 13:17
@github-actions github-actions Bot added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. area-Bzlmod Bzlmod-specific PRs, issues, and feature requests labels Dec 1, 2026
@deepalak56

deepalak56 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Replaces #32981. As discussed, this first cherry-picks #29453 (add_prefix), which #30321 depends on, then #30321, plus the add_prefix follow-up fix #30309.

Verified locally: starlark_git_repository_test and BzlmodTests pass.

git_repository checks add_prefix containment with a raw string prefix.
A normalized path can therefore select a sibling whose name shares the
checkout-root prefix, and the worker deletes that sibling before
fetching.

Require a path-component boundary (or the root itself) and cover the
destructive sibling case with a sentinel regression.

Follow-up to bazelbuild#29453.

Closes bazelbuild#30309.

PiperOrigin-RevId: 969773896
Change-Id: I7e9fbd29625c4c8c3ec3e056c13745cdfefe929c
@meteorcloudy
meteorcloudy added this pull request to the merge queue Dec 2, 2026
Merged via the queue into bazelbuild:release-9.4.0 with commit c1bd962 Dec 2, 2026
42 checks passed
@github-actions github-actions Bot removed the awaiting-review PR is awaiting review from an assigned reviewer label Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-Bzlmod Bzlmod-specific PRs, issues, and feature requests team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. 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.

4 participants