Skip to content
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

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions tools/build_defs/repo/git_worker.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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(cl, environment = ctx.os.environ | _GIT_LOCAL_ENV_VARS)
if st.return_code != 0:
_error(ctx.name, cl, st.stderr)

Expand Down Expand Up @@ -195,13 +195,35 @@ def _git_maybe_shallow(ctx, git_repo, command, *args):
return st
return _execute(ctx, git_repo, start + args_list)

# List of variables to unset when calling `git` to ensure no interference of
# operation. This is in the form of a dict that can be passed to `execute()`.
# This list is taken from the output of `git rev-parse --local-env-vars`
_GIT_LOCAL_ENV_VARS = {
"GIT_ALTERNATE_OBJECT_DIRECTORIES": None,
"GIT_CONFIG": None,
"GIT_CONFIG_PARAMETERS": None,
"GIT_CONFIG_COUNT": None,
"GIT_OBJECT_DIRECTORY": None,
"GIT_DIR": None,
"GIT_WORK_TREE": None,
"GIT_IMPLICIT_WORK_TREE": None,
"GIT_GRAFT_FILE": None,
"GIT_INDEX_FILE": None,
"GIT_NO_REPLACE_OBJECTS": None,
"GIT_REPLACE_REF_BASE": None,
"GIT_PREFIX": None,
"GIT_INTERNAL_SUPER_PREFIX": None,
"GIT_SHALLOW_FILE": None,
"GIT_COMMON_DIR": None,
}

def _execute(ctx, git_repo, args):
# "core.fsmonitor=false" disables git from spawning a file system monitor which can cause hangs when cloning a lot.
# See https://github.com/bazelbuild/bazel/issues/21438
start = ["git", "-c", "core.fsmonitor=false"]
return ctx.execute(
start + args,
environment = ctx.os.environ,
environment = ctx.os.environ | _GIT_LOCAL_ENV_VARS,
working_directory = str(git_repo.directory),
)

Expand Down
Loading