Skip to content
Open
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 prelude/decls/git_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ git_fetch = prelude_rule(
"rev": attrs.string(doc = """
Commit hash. 40 hex digits for sha1, 64 hex digits for sha256.
"""),
"update_submodules": attrs.bool(
default = False,
doc = """
Whether to initialize and update Git submodules after there worktree checkout.
"""
),
"sub_targets": attrs.list(
attrs.string(),
default = [],
Expand Down
6 changes: 6 additions & 0 deletions prelude/git/git_fetch.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,18 @@ def git_fetch_impl(ctx: AnalysisContext) -> list[Provider]:
short_path = "work-tree"
work_tree = ctx.actions.declare_output(short_path, dir = True)

if ctx.attrs.update_submodules:
update_submodules = cmd_args("--update-submodules")
else:
update_submodules = cmd_args()

cmd = [
ctx.attrs._git_fetch_tool[RunInfo],
cmd_args("--git-dir=", git_dir.as_output(), delimiter = ""),
cmd_args("--work-tree=", work_tree.as_output(), delimiter = ""),
cmd_args("--repo=", ctx.attrs.repo, delimiter = ""),
cmd_args("--rev=", rev, delimiter = ""),
update_submodules,
]
if object_format != None:
cmd.append(cmd_args("--object-format=", object_format, delimiter = ""))
Expand Down
9 changes: 8 additions & 1 deletion prelude/git/tools/git_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# above-listed licenses.

import argparse
import os
import subprocess
import sys
import time
Expand Down Expand Up @@ -51,13 +52,15 @@ class Args(NamedTuple):
object_format: ObjectFormat
repo: str
rev: str
update_submodules: bool


def arg_parse() -> Args:
parser = argparse.ArgumentParser()
parser.add_argument("--git-dir", type=Path, required=True)
parser.add_argument("--work-tree", type=Path, required=True)
parser.add_argument("--object-format", type=ObjectFormat, required=False)
parser.add_argument("--update-submodules", action='store_true', required=False)
parser.add_argument("--repo", type=str, required=True)
parser.add_argument("--rev", type=str, required=True)
return Args(**vars(parser.parse_args()))
Expand All @@ -76,7 +79,7 @@ def main() -> None:

args.work_tree.mkdir(exist_ok=True)

git = ["git", f"--git-dir={args.git_dir}", f"--work-tree={args.work_tree}"]
git = ["git", "--git-dir", args.git_dir, "--work-tree", args.work_tree]
if args.object_format is None:
object_format_args = []
else:
Expand All @@ -97,6 +100,10 @@ def main() -> None:

run([*git, "checkout", "FETCH_HEAD"], check=True)

if args.update_submodules:
git_in_worktree = ["git", "--git-dir", os.path.abspath(args.git_dir), "-C", args.work_tree]
run([*git_in_worktree, "submodule", "update", "--init"], check=True)


if __name__ == "__main__":
main()
Loading