From 3d8e1224f4faff79f42a57be218c93732b4e3892 Mon Sep 17 00:00:00 2001 From: Brandon Jones Date: Tue, 1 Oct 2024 12:09:27 +0100 Subject: [PATCH] fix: pass recursive option through and always fetch root --- git/fetch/repository.bzl | 2 +- lib/fetch.bzl | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/git/fetch/repository.bzl b/git/fetch/repository.bzl index 967d36b..0cb2384 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 9ed02a4..efdf4b4 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) -- GitLab