diff --git a/git/fetch/repository.bzl b/git/fetch/repository.bzl index 967d36b59cae2123034216fe328c27afee67eade..0cb238494059d14ad09181f78e20eb0be46f7e77 100644 --- a/git/fetch/repository.bzl +++ b/git/fetch/repository.bzl @@ -26,7 +26,7 @@ def implementation(rctx): canonical["commit"] = commit canonical["reference"] = reference - modules = _fetch(rctx, commit = commit, dir = dir, reference = reference) + modules = _fetch(rctx, commit = commit, dir = dir, reference = reference, recursive = rctx.attr.recursive) _dir(rctx, dir = dir) diff --git a/lib/fetch.bzl b/lib/fetch.bzl index 9ed02a486aa7a3e90cf4d76af1d4079cee33ff49..efdf4b4ef7f677c57e652b4333203b5d537fde2f 100644 --- a/lib/fetch.bzl +++ b/lib/fetch.bzl @@ -150,7 +150,7 @@ Fallback methods activate when a `git` server does not support single SHA fetche The fetch ultimately falls back to retrieving all tags and branches. It is unexpected not to be able to find the `{commit}` in the repository after a full depth, through fetch. Check that the SHA is valid and exists in the remote repository. """.format(remote = remote, commit = commit)) -def _submodules(rctx, module, *, dir, git): +def _submodules(rctx, module, *, dir, git, recursive = True): """ Fetches a module and determines the submodules, if any. @@ -178,6 +178,9 @@ def _submodules(rctx, module, *, dir, git): if result.return_code != 0: fail("Failed to fetch `{}#{}`: {}".format(module.remote, module.commit, result.stderr)) + if not recursive: + return () + head = dir.get_child("HEAD") rctx.file(head, module.commit, executable = False) @@ -216,18 +219,16 @@ def _modules(rctx, *, remote, commit, reference, dir, git, recursive = True): commit = commit, reference = reference, path = ".", + nested = tuple([]), ) modules = [root] - if not recursive: - return modules - for i in range(0, 0x7ee7babe): if len(modules) <= i: break module = modules[i] - nested = _submodules(rctx, module, git = git, dir = dir) + nested = _submodules(rctx, module, git = git, dir = dir, recursive = recursive) kw = structs.to_dict(module) kw["nested"] = tuple([m.path for m in nested]) modules[i] = struct(**kw)