-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make git_repository()
ignore GIT_
env vars
#24204
Conversation
tools/build_defs/repo/git_worker.bzl
Outdated
@@ -126,7 +126,7 @@ def _update(ctx, git_repo): | |||
|
|||
def init(ctx, git_repo): | |||
cl = ["git", "init", str(git_repo.directory)] | |||
st = ctx.execute(cl, environment = ctx.os.environ) | |||
st = ctx.execute(_strip_git_vars(cl), environment = ctx.os.environ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove those env vars from ctx.os.environ instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that you can only force variables to new values (e.g. the empty value), but can't remove them. Or maybe that works if they are set to None
? If not, that would probably be a reasonable feature request :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fmeum is correct. This was my first thought, but setting to the empty string upsets Git, and setting to None upsets Bazel. And yes, being able to unset a variable with None would be a great FR!
Also, I would have liked to have been able to unset a variable with --repo_env
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the problem (as indicated by the test results) is that this doesn't work on Windows... We might need to implement that FR first :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I saw the Windows failures. I'll dig into that and see if this can reasonably be solved within this repo rule.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, I sent #24221, so it may be more efficient to wait for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for that! This is definitely much cleaner. However, I still need a solution for Bazel 7. So I will continue to get this working in Windows.
Perhaps this PR (once I fix Windows) could go in and be cherry-picked into the 7 branch, then a follow-up could replace the solution based on your PR? I'm not sure what the process is for point releases.
Or maybe it makes more sense to bring your PR into Bazel 7?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, if there is ever a 7.5 release, we could just cherry-pick both commits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have rebased and changed my PR to use your new feature. I haven't been able to get my Windows build of Bazel to pass that failing test even at HEAD, so I'm going to lean on the merge checks here. 🤞
tools/build_defs/repo/git_worker.bzl
Outdated
return [ | ||
"bash", | ||
"-c", | ||
"unset $(git rev-parse --local-env-vars); " + " ".join(args), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it clear that unsetting all GIT_
vars is correct? What about something like GIT_SSH
or GIT_SSL_NO_VERIFY
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$ git rev-parse --local-env-vars
GIT_ALTERNATE_OBJECT_DIRECTORIES
GIT_CONFIG
GIT_CONFIG_PARAMETERS
GIT_CONFIG_COUNT
GIT_OBJECT_DIRECTORY
GIT_DIR
GIT_WORK_TREE
GIT_IMPLICIT_WORK_TREE
GIT_GRAFT_FILE
GIT_INDEX_FILE
GIT_NO_REPLACE_OBJECTS
GIT_REPLACE_REF_BASE
GIT_PREFIX
GIT_INTERNAL_SUPER_PREFIX
GIT_SHALLOW_FILE
GIT_COMMON_DIR
So this doesn't snarf GIT_SSH
or GIT_SSL_NO_VERIFY
. I'll dig info the Windows issue.
This ensures that this repository rule cannot be influenced by these environment variables, particularly `GIT_DIR`, keeping the operation limited to the directory specified by the `repository_ctx`. In particular, this ensures that calling Bazel (e.g. `bazel test`) from within a Git hook will work reliably. Git hooks set `GIT_DIR` (among others), which can cause the repository rule's invocations of `git` to misbehave. https://git-scm.com/docs/githooks When using Git worktrees and calling Bazel from a Git hook, it has been observed that `git_repository()` will not only fail, but will also set `core.bare = true`, breaking the user's clone.
5d10ac1
to
c541924
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@bazel-io fork 8.0.0 |
This ensures that this repository rule cannot be influenced by these environment variables, particularly `GIT_DIR`, keeping the operation limited to the directory specified by the `repository_ctx`. In particular, this ensures that calling Bazel (e.g. `bazel test`) from within a Git hook will work reliably. Git hooks set `GIT_DIR` (among others), which can cause the repository rule's invocations of `git` to misbehave. https://git-scm.com/docs/githooks When using Git worktrees and calling Bazel from a Git hook, it has been observed that `git_repository()` will not only fail, but will also set `core.bare = true`, breaking the user's clone. Fixes bazelbuild#24199. Closes bazelbuild#24204. PiperOrigin-RevId: 695642299 Change-Id: Id81e32194117cd8996408b236a6a88a20b14910b
This ensures that this repository rule cannot be influenced by these environment variables, particularly `GIT_DIR`, keeping the operation limited to the directory specified by the `repository_ctx`. In particular, this ensures that calling Bazel (e.g. `bazel test`) from within a Git hook will work reliably. Git hooks set `GIT_DIR` (among others), which can cause the repository rule's invocations of `git` to misbehave. https://git-scm.com/docs/githooks When using Git worktrees and calling Bazel from a Git hook, it has been observed that `git_repository()` will not only fail, but will also set `core.bare = true`, breaking the user's clone. Fixes #24199. Closes #24204. PiperOrigin-RevId: 695642299 Change-Id: Id81e32194117cd8996408b236a6a88a20b14910b Commit 89115d9 Co-authored-by: Richard Woodbury <[email protected]>
This ensures that this repository rule cannot be influenced by these environment variables, particularly `GIT_DIR`, keeping the operation limited to the directory specified by the `repository_ctx`. In particular, this ensures that calling Bazel (e.g. `bazel test`) from within a Git hook will work reliably. Git hooks set `GIT_DIR` (among others), which can cause the repository rule's invocations of `git` to misbehave. https://git-scm.com/docs/githooks When using Git worktrees and calling Bazel from a Git hook, it has been observed that `git_repository()` will not only fail, but will also set `core.bare = true`, breaking the user's clone. Fixes bazelbuild#24199. Closes bazelbuild#24204. PiperOrigin-RevId: 695642299 Change-Id: Id81e32194117cd8996408b236a6a88a20b14910b
This ensures that this repository rule cannot be influenced by these environment variables, particularly
GIT_DIR
, keeping the operation limited to the directory specified by therepository_ctx
.In particular, this ensures that calling Bazel (e.g.
bazel test
) from within a Git hook will work reliably. Git hooks setGIT_DIR
(among others), which can cause the repository rule's invocations ofgit
to misbehave. https://git-scm.com/docs/githooksWhen using Git worktrees and calling Bazel from a Git hook, it has been observed that
git_repository()
will not only fail, but will also setcore.bare = true
, breaking the user's clone.Fixes #24199.