-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Support checking out the repo's default branch in git_repository/new_git_repository rule
#27611
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
Conversation
fmeum
left a comment
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 would use this!
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.
Pull Request Overview
This PR adds support for checking out a Git repository's default branch when using git_repository or new_git_repository rules without specifying a branch, tag, or commit. Previously, at least one of these attributes was required; now they are all optional, allowing the repository's default branch to be checked out automatically.
- Updated validation logic to allow zero or one of
branch,tag, orcommit(previously required exactly one) - Added default branch handling in git_worker.bzl using
origin/HEAD - Updated documentation to reflect the new optional behavior
- Added test coverage for the default branch scenario in both shell and Java tests
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tools/build_defs/repo/git_worker.bzl | Added default branch case handling using origin/HEAD and updated documentation |
| tools/build_defs/repo/git.bzl | Changed validation from "exactly one" to "at most one" and updated rule documentation |
| src/test/shell/bazel/starlark_git_repository_test.sh | Added tests for default branch checkout and removed obsolete error test |
| src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/GitRepositoryBlackBoxTest.java | Added testCloneAtDefaultBranch test and updated class documentation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
0111db3 to
e99ce2a
Compare
meteorcloudy
left a comment
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 9.0.0 |
|
Thank you for this well-thought out, well-explained and well-written PR! |
…ew_git_repository` rule The `git_repository` and `new_git_repository` rules currently require not only the remote repository URI to be specified but also either the branch, tag or revision (commit) to check out. This PR removes the latter requirement. If no branch, tag or revision are specified, the repo's default branch will be checked out. The main reason for introducing this proposed change, is because I noticed certain Bazel rules already generate `git_repository` targets from git URIs or other git repo specs that might not have a branch, tag or revision specified. These rules then typically default to a branch name of `master`, which is not correct in general. This change will allow those rules to simply omit the branch, tag and revision from the generated `git_repository` targets, to check out the repo's default branch. An alternative, more explicit, interface for specifying that the default branch is to be checked out, would have been to add an optional boolean `default_branch` attribute to the `git_repository` and `new_git_repository` rules. The presence of that attribute would be mutually exclusive with the presence of `branch`, `tag` and `commit`. Let me know if that interface is preferable. Addresses issue bazelbuild#27610. Closes bazelbuild#27611. PiperOrigin-RevId: 833710273 Change-Id: I7bc18efcbcfcaba61bf27052fecceb50336d2eb3
Thank you, glad to be contributing back! I have a question though: I see the PR has been forked off into the 9.0.0 release branch but not into the 8.5.0 branch. I'm not aware of the policy around this, but at least in terms of backwards compatibility it should be okay to include these changes in 8.5.0 as well. |
|
Looks like we need another rc for 8.5.0, I'm fine with backporting to 8.5.0 |
|
@bazel-io fork 8.5.0 |
…ew_git_repository` rule The `git_repository` and `new_git_repository` rules currently require not only the remote repository URI to be specified but also either the branch, tag or revision (commit) to check out. This PR removes the latter requirement. If no branch, tag or revision are specified, the repo's default branch will be checked out. The main reason for introducing this proposed change, is because I noticed certain Bazel rules already generate `git_repository` targets from git URIs or other git repo specs that might not have a branch, tag or revision specified. These rules then typically default to a branch name of `master`, which is not correct in general. This change will allow those rules to simply omit the branch, tag and revision from the generated `git_repository` targets, to check out the repo's default branch. An alternative, more explicit, interface for specifying that the default branch is to be checked out, would have been to add an optional boolean `default_branch` attribute to the `git_repository` and `new_git_repository` rules. The presence of that attribute would be mutually exclusive with the presence of `branch`, `tag` and `commit`. Let me know if that interface is preferable. Addresses issue bazelbuild#27610. Closes bazelbuild#27611. PiperOrigin-RevId: 833710273 Change-Id: I7bc18efcbcfcaba61bf27052fecceb50336d2eb3
…tory`/`new_git_repository` rule (#27701) The `git_repository` and `new_git_repository` rules currently require not only the remote repository URI to be specified but also either the branch, tag or revision (commit) to check out. This PR removes the latter requirement. If no branch, tag or revision are specified, the repo's default branch will be checked out. The main reason for introducing this proposed change, is because I noticed certain Bazel rules already generate `git_repository` targets from git URIs or other git repo specs that might not have a branch, tag or revision specified. These rules then typically default to a branch name of `master`, which is not correct in general. This change will allow those rules to simply omit the branch, tag and revision from the generated `git_repository` targets, to check out the repo's default branch. An alternative, more explicit, interface for specifying that the default branch is to be checked out, would have been to add an optional boolean `default_branch` attribute to the `git_repository` and `new_git_repository` rules. The presence of that attribute would be mutually exclusive with the presence of `branch`, `tag` and `commit`. Let me know if that interface is preferable. Addresses issue #27610. Closes #27611. PiperOrigin-RevId: 833710273 Change-Id: I7bc18efcbcfcaba61bf27052fecceb50336d2eb3 Commit ee3af97 Co-authored-by: Pieter Agten <pieter.agten@gmail.com>
…tory`/`new_git_repository` rule (#27705) The `git_repository` and `new_git_repository` rules currently require not only the remote repository URI to be specified but also either the branch, tag or revision (commit) to check out. This PR removes the latter requirement. If no branch, tag or revision are specified, the repo's default branch will be checked out. The main reason for introducing this proposed change, is because I noticed certain Bazel rules already generate `git_repository` targets from git URIs or other git repo specs that might not have a branch, tag or revision specified. These rules then typically default to a branch name of `master`, which is not correct in general. This change will allow those rules to simply omit the branch, tag and revision from the generated `git_repository` targets, to check out the repo's default branch. An alternative, more explicit, interface for specifying that the default branch is to be checked out, would have been to add an optional boolean `default_branch` attribute to the `git_repository` and `new_git_repository` rules. The presence of that attribute would be mutually exclusive with the presence of `branch`, `tag` and `commit`. Let me know if that interface is preferable. Addresses issue #27610. Closes #27611. PiperOrigin-RevId: 833710273 Change-Id: I7bc18efcbcfcaba61bf27052fecceb50336d2eb3 Commit ee3af97 --------- Co-authored-by: Pieter Agten <pieter.agten@gmail.com> Co-authored-by: Yun Peng <pcloudy@google.com>
The
git_repositoryandnew_git_repositoryrules currently require not only the remote repository URI to be specified but also either the branch, tag or revision (commit) to check out. This PR removes the latter requirement. If no branch, tag or revision are specified, the repo's default branch will be checked out.The main reason for introducing this proposed change, is because I noticed certain Bazel rules already generate
git_repositorytargets from git URIs or other git repo specs that might not have a branch, tag or revision specified. These rules then typically default to a branch name ofmaster, which is not correct in general. This change will allow those rules to simply omit the branch, tag and revision from the generatedgit_repositorytargets, to check out the repo's default branch.An alternative, more explicit, interface for specifying that the default branch is to be checked out, would have been to add an optional boolean
default_branchattribute to thegit_repositoryandnew_git_repositoryrules. The presence of that attribute would be mutually exclusive with the presence ofbranch,tagandcommit. Let me know if that interface is preferable.Addresses issue #27610.