You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
P3We're not considering working on this, but happy to review a PR. (No assignee)team-ExternalDepsExternal dependency handling, remote repositiories, WORKSPACE file.type: feature request
have new_git_repository rules use the repository_cache
Feature requests: what underlying problem are you trying to solve with this feature?
I'd like to be able to reuse external git dependencies like one can reuse new_http_archive
Reacted by Markus Padourek, Marc Plano-Lesay, Emran Batmanghelich, Pierre Fenoll, Daniel Toyama, Vladimir Rutsky, darkdragon-001, hovind, iMostfa and Pdom
I think, in general it is a good idea, especially as git basically is a content-addressable storage, so even individual shared blobs could be avoided being downloaded again.
Note that we're moving from the native git_repository rules to the Skylark version. So, assuming you're given a directory that you can use as cache, what would be the appropriate git commands to make best use of it?
As mentioned in #5086, one possible way forward might be telling the Skylark git_repository rule (e.g., via an environment variable) about the location of a git repository on the local machine that might be used as a cache. But still, I'm not sure what the best option is.
we wanted to get the path to the cache folder either from environment or command line arguments.
We tried using ctx.os.environ, but adding a new environment variable didn't affect its value
We tired looking for a way to get a command line parameter value via ctx and found no such way
we wanted to get the path to the cache folder either from environment or command line arguments. We tried using ctx.os.environ, but adding a new environment variable didn't affect its value
ctx.os.environ does refelect the invocation environment; however, a repository is only invalidated based on the declared environment variables—but you can always use bazel sync. (Note that the cache location should not invalidate the repository, as its content do not depend on the location of the cache.)
It's worth to note that #7424 has almost finished an implementation of git_repository cache but was abandoned as the author has no capacity to support it. Whoever want to pick up this issue should consider using it as reference.
I just want to note that in upstream Git core, Microsoft's Scalar is being integrated into contrib dir and is planned to eventually integrate to be part of Git itself. If you are not familiar with Scalar, it's a high level 'git repository manager' command where it helps:
Set a sane default git configs
Help cache all git repositories it manage
Setup maintenance background jobs on top of the cache and the managed repositories
While (3) has been merged into Git Core as git-maintenance recently, (1) and (2) functionality is still being worked on. I would suggest that the repository cache adopt the same caching convention as Scalar as there are some overlapping interests between (a) Bazel users and (b) Monorepo workflow users and (c) Scalar users.
On a high level, this is how Scalar git repository cache works:
I am gloating over the details, but using git clone --reference would setup a .git/info/alternates file pointing back to $CACHE_DIR. This helps signal git to reuse the Object Database(ODB) inside cache dir.
Using git clone --reference-if-able, in my opinion, is a better approach than git worktree as the cloned repo comes with a separate set of git configs and git index which let you apply another level of modification (i.e. applying a sparse-checkout) without affecting/leaving residual states in the cache dir.
However to make offline cache support to work, implementer most likely wont be able to use git clone directly. They should consider using a set of plumping command instead to prioritize making offline cache works.
Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 14 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-bazeler". Please reach out to the triage team (@bazelbuild/triage) if you think this issue is still relevant or you are interested in getting the issue resolved.
I ran across this issue just yesterday: a repo I'm trying to build has some submodules on a very slow server (and because they are submodules, I can't just choose a faster replica).
Side note: one trick to reducing the issues that slow downloads cause (at least while developing the injected BUILD file) is to avoid all need to change anything actually in git_repository.build_file by making is be nothing more than a reference back to a .bzl file in the root project:
i just stumped upon this issue, the build suppose to happen offline, so i would like to copy the cache to an offline server.
However if the project is using git_repository i am not able to build offline.
P3We're not considering working on this, but happy to review a PR. (No assignee)team-ExternalDepsExternal dependency handling, remote repositiories, WORKSPACE file.type: feature request
Activity
aehlig commentedon May 15, 2018
I think, in general it is a good idea, especially as git basically is a content-addressable storage, so even individual shared blobs could be avoided being downloaded again.
Note that we're moving from the native
git_repositoryrules to the Skylark version. So, assuming you're given a directory that you can use as cache, what would be the appropriategitcommands to make best use of it?ittaiz commentedon Jul 16, 2018
@aehlig given your work on WORKSPACE.resolved and git_repository this sounds like it might be super relevant, right?
aehlig commentedon Jul 16, 2018
As mentioned in #5086, one possible way forward might be telling the Skylark
git_repositoryrule (e.g., via an environment variable) about the location of a git repository on the local machine that might be used as a cache. But still, I'm not sure what the best option is.aoded commentedon Aug 13, 2018
Hi @aehlig, we would appreciate some help with this :)
We tried to work on this feature, and while modifying this method -
bazel/tools/build_defs/repo/git.bzl
Line 18 in ca2733c
We tried using ctx.os.environ, but adding a new environment variable didn't affect its value
We tired looking for a way to get a command line parameter value via ctx and found no such way
Thanks!
Oded
aehlig commentedon Aug 14, 2018
ctx.os.environdoes refelect the invocation environment; however, a repository is only invalidated based on the declared environment variables—but you can always usebazel sync. (Note that the cache location should not invalidate the repository, as its content do not depend on the location of the cache.)3 remaining items
Mount Bazel repository_cache, Go mod cache and Go build cache as volumes
sluongng commentedon Feb 15, 2022
It's worth to note that #7424 has almost finished an implementation of git_repository cache but was abandoned as the author has no capacity to support it. Whoever want to pick up this issue should consider using it as reference.
I just want to note that in upstream Git core, Microsoft's Scalar is being integrated into
contribdir and is planned to eventually integrate to be part of Git itself. If you are not familiar with Scalar, it's a high level 'git repository manager' command where it helps:While (3) has been merged into Git Core as git-maintenance recently, (1) and (2) functionality is still being worked on. I would suggest that the repository cache adopt the same caching convention as Scalar as there are some overlapping interests between (a) Bazel users and (b) Monorepo workflow users and (c) Scalar users.
On a high level, this is how Scalar git repository cache works:
I am gloating over the details, but using
git clone --referencewould setup a.git/info/alternatesfile pointing back to $CACHE_DIR. This helps signal git to reuse the Object Database(ODB) inside cache dir.Using
git clone --reference-if-able, in my opinion, is a better approach thangit worktreeas the cloned repo comes with a separate set of git configs and git index which let you apply another level of modification (i.e. applying a sparse-checkout) without affecting/leaving residual states in the cache dir.However to make offline cache support to work, implementer most likely wont be able to use
git clonedirectly. They should consider using a set of plumping command instead to prioritize making offline cache works.Question: what is the best way for user to configure $CACHE_DIR location? Environment variable or a bazel flag?
github-actions commentedon Jun 13, 2023
Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 14 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-bazeler". Please reach out to the triage team (
@bazelbuild/triage) if you think this issue is still relevant or you are interested in getting the issue resolved.bcsgh commentedon Jun 13, 2023
I ran across this issue just yesterday: a repo I'm trying to build has some submodules on a very slow server (and because they are submodules, I can't just choose a faster replica).
fmeum commentedon Jun 13, 2023
Cc @Wyverald
bcsgh commentedon Dec 19, 2023
Side note: one trick to reducing the issues that slow downloads cause (at least while developing the injected
BUILDfile) is to avoid all need to change anything actually ingit_repository.build_fileby making is be nothing more than a reference back to a.bzlfile in the root project:That also works with
git_repository.build_file_contentand for something that small that's likely the way to go.amfern commentedon Jul 24, 2024
i just stumped upon this issue, the build suppose to happen offline, so i would like to copy the cache to an offline server.
However if the project is using git_repository i am not able to build offline.
Use archive_override for ja_usage_dict instead of git_override.
Added userspace device mapper library
fmeum commentedon Aug 14, 2025
As of Bazel 8.3.1,
git_repositorywithcommitspecified is marked as reproducible and thus uses the--repo_contents_cache.tmewett commentedon Sep 2, 2025
Nice, thank you!
The git_repository docs still contain this:
What should it say instead now? Should it be removed entirely? Or something like this?