@bazel_tools//tools/build_defs/repo:git.bzl.
Rules for cloning external git repositories.
git_repository
load(“@bazel//tools/build_defs/repo:git.bzl”, “git_repository”)git_repository(name, branch, build_file, build_file_content, canonical_id, commit, init_submodules, patch_args, patch_cmds, patch_cmds_win, patch_strip, patch_tool, patches, recursive_init_submodules, remote, remote_module_file_integrity, remote_module_file_urls, remote_patch_strip, remote_patches, shallow_since, sparse_checkout_file, sparse_checkout_patterns, strip_prefix, tag, verbose, workspace_file, workspace_file_content)Clone an external git repository. Clones a Git repository, checks out the specified branch, tag, or commit, and makes its targets available for binding. If no branch, tag or commit is specified, check out the repository’s default branch. Also determine the id and date of the commit that was checked out, and return a dict with parameters that provide a reproducible version of this rule (which a tag or branch not necessarily is). Bazel will first try to perform a shallow fetch of only the specified commit. If that fails (usually due to missing server support), it will fall back to a full fetch of the repository. Prefer
http_archive to git_repository.
The reasons are:
- Git repository rules depend on system
git(1)whereas the HTTP downloader is built into Bazel and has no system dependencies. http_archivesupports a list ofurlsas mirrors, andgit_repositorysupports only a singleremote.http_archiveworks with the repository cache, but notgit_repository. See #5116 for more information.
name | Name; required A unique name for this repository. |
branch | String; optional branch in the remote repository to checked out. Precisely one of branch, tag, or commit must be specified. |
build_file | Label; optional The file to use as the BUILD file for this repository. This attribute is an absolute label (use ’@//’ for the main repo). The file does not need to be named BUILD, but can be (something like BUILD.new-repo-name may work well for distinguishing it from the repository’s actual BUILD files). |
build_file_content | String; optional The content for the BUILD file for this repository. |
canonical_id | String; optional A canonical ID of the file downloaded.If specified and non-empty, Bazel will not take the file from cache, unless it was added to the cache by a request with the same canonical ID.If unspecified or empty, Bazel by default uses the URLs of the file as the canonical ID. This helps catch the common mistake of updating the URLs without also updating the hash, resulting in builds that succeed locally but fail on machines without the file in the cache. This behavior can be disabled with —repo_env=BAZEL_HTTP_RULES_URLS_AS_DEFAULT_CANONICAL_ID=0. |
commit | String; optional specific commit to be checked out. Precisely one of branch, tag, or commit must be specified. |
init_submodules | Boolean; optional Whether to clone submodules in the repository. |
patch_args | List of strings; optional The arguments given to the patch tool. Defaults to -p0 (see the |
patch_cmds | List of strings; optional Sequence of Bash commands to be applied on Linux/Macos after patches are applied. |
patch_cmds_win | List of strings; optional Sequence of Powershell commands to be applied on Windows after patches are applied. If this attribute is not set, patch_cmds will be executed on Windows, which requires Bash binary to exist. |
patch_strip | Integer; optional When set to |
patch_tool | String; optional The patch(1) utility to use. If this is specified, Bazel will use the specified patch tool instead of the Bazel-native patch implementation. |
patches | List of labels; optional A list of files that are to be applied as patches after extracting the archive. By default, it uses the Bazel-native patch implementation which doesn’t support binary patch, but Bazel will fall back to use patch command line tool if |
recursive_init_submodules | Boolean; optional Whether to clone submodules recursively in the repository. |
remote | String; required The URI of the remote Git repository |
remote_module_file_integrity | String; optional For internal use only. |
remote_module_file_urls | List of strings; optional For internal use only. |
remote_patch_strip | Integer; optional The number of leading slashes to be stripped from the file name in the remote patches. |
remote_patches | Dictionary: String -> String; optional A map of patch file URL to its integrity value, they are applied after cloning the repository and before applying patch files from the |
shallow_since | String; optional an optional date, not after the specified commit; the argument is not allowed if a tag or branch is specified (which can always be cloned with —depth=1). Setting such a date close to the specified commit may allow for a shallow clone of the repository even if the server does not support shallow fetches of arbitrary commits. Due to bugs in git’s —shallow-since implementation, using this attribute is not recommended as it may result in fetch failures. |
sparse_checkout_file | Label; optional File containing .gitignore-style patterns for a sparse checkout of files in this repository. Either |
sparse_checkout_patterns | List of strings; optional Sequence of patterns for a sparse checkout of files in this repository. |
strip_prefix | String; optional A directory prefix to strip from the extracted files. |
tag | String; optional tag in the remote repository to checked out. Precisely one of branch, tag, or commit must be specified. |
verbose | Boolean; optional |
workspace_file | Label; optional No-op attribute; do not use. |
workspace_file_content | String; optional No-op attribute; do not use. |
BAZEL_HTTP_RULES_URLS_AS_DEFAULT_CANONICAL_ID
new_git_repository
load(“@bazel//tools/build_defs/repo:git.bzl”, “new_git_repository”)new_git_repository(name, branch, build_file, build_file_content, canonical_id, commit, init_submodules, patch_args, patch_cmds, patch_cmds_win, patch_strip, patch_tool, patches, recursive_init_submodules, remote, remote_module_file_integrity, remote_module_file_urls, remote_patch_strip, remote_patches, shallow_since, sparse_checkout_file, sparse_checkout_patterns, strip_prefix, tag, verbose, workspace_file, workspace_file_content)Deprecated - use the drop-in replacement ‘git_repository’ instead ATTRIBUTES
name | Name; required A unique name for this repository. |
branch | String; optional branch in the remote repository to checked out. Precisely one of branch, tag, or commit must be specified. |
build_file | Label; optional The file to use as the BUILD file for this repository. This attribute is an absolute label (use ’@//’ for the main repo). The file does not need to be named BUILD, but can be (something like BUILD.new-repo-name may work well for distinguishing it from the repository’s actual BUILD files). |
build_file_content | String; optional The content for the BUILD file for this repository. |
canonical_id | String; optional A canonical ID of the file downloaded.If specified and non-empty, Bazel will not take the file from cache, unless it was added to the cache by a request with the same canonical ID.If unspecified or empty, Bazel by default uses the URLs of the file as the canonical ID. This helps catch the common mistake of updating the URLs without also updating the hash, resulting in builds that succeed locally but fail on machines without the file in the cache. This behavior can be disabled with —repo_env=BAZEL_HTTP_RULES_URLS_AS_DEFAULT_CANONICAL_ID=0. |
commit | String; optional specific commit to be checked out. Precisely one of branch, tag, or commit must be specified. |
init_submodules | Boolean; optional Whether to clone submodules in the repository. |
patch_args | List of strings; optional The arguments given to the patch tool. Defaults to -p0 (see the |
patch_cmds | List of strings; optional Sequence of Bash commands to be applied on Linux/Macos after patches are applied. |
patch_cmds_win | List of strings; optional Sequence of Powershell commands to be applied on Windows after patches are applied. If this attribute is not set, patch_cmds will be executed on Windows, which requires Bash binary to exist. |
patch_strip | Integer; optional When set to |
patch_tool | String; optional The patch(1) utility to use. If this is specified, Bazel will use the specified patch tool instead of the Bazel-native patch implementation. |
patches | List of labels; optional A list of files that are to be applied as patches after extracting the archive. By default, it uses the Bazel-native patch implementation which doesn’t support binary patch, but Bazel will fall back to use patch command line tool if |
recursive_init_submodules | Boolean; optional Whether to clone submodules recursively in the repository. |
remote | String; required The URI of the remote Git repository |
remote_module_file_integrity | String; optional For internal use only. |
remote_module_file_urls | List of strings; optional For internal use only. |
remote_patch_strip | Integer; optional The number of leading slashes to be stripped from the file name in the remote patches. |
remote_patches | Dictionary: String -> String; optional A map of patch file URL to its integrity value, they are applied after cloning the repository and before applying patch files from the |
shallow_since | String; optional an optional date, not after the specified commit; the argument is not allowed if a tag or branch is specified (which can always be cloned with —depth=1). Setting such a date close to the specified commit may allow for a shallow clone of the repository even if the server does not support shallow fetches of arbitrary commits. Due to bugs in git’s —shallow-since implementation, using this attribute is not recommended as it may result in fetch failures. |
sparse_checkout_file | Label; optional File containing .gitignore-style patterns for a sparse checkout of files in this repository. Either |
sparse_checkout_patterns | List of strings; optional Sequence of patterns for a sparse checkout of files in this repository. |
strip_prefix | String; optional A directory prefix to strip from the extracted files. |
tag | String; optional tag in the remote repository to checked out. Precisely one of branch, tag, or commit must be specified. |
verbose | Boolean; optional |
workspace_file | Label; optional No-op attribute; do not use. |
workspace_file_content | String; optional No-op attribute; do not use. |