From 421386178d572969bbe20f1f195211da1a75485c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20GRALL?= Date: Fri, 9 Jan 2026 14:45:36 +0100 Subject: [PATCH 1/2] [FIX] oops-sub-add: error path --- oops/git/submodules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oops/git/submodules.py b/oops/git/submodules.py index b456893..bda7a2b 100644 --- a/oops/git/submodules.py +++ b/oops/git/submodules.py @@ -12,7 +12,7 @@ class GitSubmodules: """Class for handling git submodule operations.""" - path: str + path: str = "" def add(self, url: str, name: str, path: str, branch: Optional[str] = None) -> None: """Add a git submodule to the repository. From 40d8951131e48f05f52fdb5e4ad82fc32c127475 Mon Sep 17 00:00:00 2001 From: Frederic Date: Tue, 10 Feb 2026 10:55:16 +0100 Subject: [PATCH 2/2] chore(add) : use git for oops-sub-add --- oops/commands/submodules/add.py | 44 +++++++++++++++++---------------- oops/core/messages.py | 4 +-- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/oops/commands/submodules/add.py b/oops/commands/submodules/add.py index 371c52a..128738c 100644 --- a/oops/commands/submodules/add.py +++ b/oops/commands/submodules/add.py @@ -4,11 +4,12 @@ from pathlib import Path import click +from git import Repo + +from oops.utils.git import is_pull_request, read_gitmodules from oops.core.config import config from oops.core.messages import commit_messages -from oops.git.core import GitRepository -from oops.git.submodules import GitSubmodules from oops.utils.helpers import str_to_list from oops.utils.io import ( desired_path, @@ -89,9 +90,7 @@ def main( # noqa: C901, PLR0915, PLR0913 no_commit = options["no_commit"] dry_run = options["dry_run"] - # FIXME: use Repo from gitpython - repo = GitRepository() - submodules = GitSubmodules() + repo = Repo() # Compute target path and name try: @@ -103,12 +102,14 @@ def main( # noqa: C901, PLR0915, PLR0913 sub_path_str = desired_path( url, prefix=base_dir, pull_request=bool(pull_request), suffix=pull_request or None ) - sub_path = repo.path / sub_path_str + sub_path = Path(repo.working_dir) / sub_path_str sub_name = name or f"{owner}/{repo_name}" + if bool(pull_request): + sub_name = f"PRs/{sub_name}/{pull_request}" # Plan summary rows = [ - ["Repo Root", repo.path], + ["Repo Root", repo.working_dir], ["URL", url], ["Branch", branch], ["Submodule name", sub_name], @@ -132,33 +133,35 @@ def main( # noqa: C901, PLR0915, PLR0913 # Add submodule click.echo("[add] git submodule add") - # FIXME: checkout to the branch before commit - submodules.add(url, sub_name, sub_path_str, branch=branch) + repo.create_submodule( + name=sub_name, + path=sub_path_str, + url=url, + branch=branch, + ) # Pin branch in .gitmodules (redundant but explicit) click.echo("[config] record branch in .gitmodules") if branch: - submodules.set_branch(sub_name, branch) - - # Sync and fetch content - submodules.sync() - submodules.update() + gitmodules = read_gitmodules(repo) + click.echo(f"Setting branch {branch!r} for submodule {sub_name!r}...") + gitmodules.set_value(f'submodule "{sub_name}"', "branch", branch) created_links = [] def create_symlink(addon_dir: Path): link_name = f"{addon_dir.name}" - link_path = repo.path / link_name + link_path = Path(repo.working_dir) / link_name # Determine relative target from repo root to the addon_dir - target_rel = relpath(repo.path, addon_dir) + target_rel = relpath(Path(repo.working_dir), addon_dir) if link_path.exists() or link_path.is_symlink(): click.echo(f" [skip] {link_name} already exists") return os.symlink(target_rel, link_path) created_links.append(link_name) # Stage symlink - repo.add([link_name]) + repo.index.add([link_name]) if auto_symlinks or addons: click.echo("[scan] detecting addon folders…") @@ -185,12 +188,11 @@ def create_symlink(addon_dir: Path): click.echo(f"Addons not found: {human_readable(diff)}") # Stage .gitmodules and submodule path - repo.add([".gitmodules", sub_path_str]) + repo.index.add([".gitmodules", sub_path_str]) if not no_commit: - repo.commit( - commit_messages.submodule_add.format(name=sub_name), - description=commit_messages.submodule_add_desc.format( + repo.index.commit( + commit_messages.submodule_add.format(name=sub_name, url=url, branch=branch, path=sub_path_str, diff --git a/oops/core/messages.py b/oops/core/messages.py index c36cf48..c5b1c74 100644 --- a/oops/core/messages.py +++ b/oops/core/messages.py @@ -20,8 +20,8 @@ class CommitMessages: submodules_replace: str = ( "chore(submodules): replace submodule(s) and update symlinks\n\n{description}" ) - submodule_add: str = "chore(submodules): add submodule {name}" - submodule_add_desc: str = """ + submodule_add: str = """chore(submodules): add submodule {name}" + - url: {url} - branch: {branch} - path: {path}