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

Delete .git directory from git_repository external repositories when using strip_prefix #18271

Closed
Closed
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions src/test/shell/bazel/starlark_git_repository_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ EOF
bazel run //planets:planet-info >& $TEST_log \
|| echo "Expected build/run to succeed"
expect_log "Pluto is a dwarf planet"

git_repos_count=$(find $(bazel info output_base)/external/pluto -type d -name .git | wc -l)
assert_equals $git_repos_count 0
}

function test_git_repository() {
Expand Down Expand Up @@ -290,6 +293,9 @@ EOF
else
expect_log "Pluto is a dwarf planet"
fi

git_repos_count=$(find $(bazel info output_base)/external/pluto -type d -name .git | wc -l)
assert_equals $git_repos_count 0
}

# Test cloning a Git repository that has a submodule using the
Expand Down
5 changes: 4 additions & 1 deletion tools/build_defs/repo/git.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ def _git_repository_implementation(ctx):
update = _clone_or_update_repo(ctx)
workspace_and_buildfile(ctx)
patch(ctx)
ctx.delete(ctx.path(".git"))
if ctx.attr.strip_prefix:
ctx.delete(ctx.path(".tmp_git_root/.git"))
else:
ctx.delete(ctx.path(".git"))
return _update_git_attrs(ctx.attr, _common_attrs.keys(), update)

git_repository = repository_rule(
Expand Down