respect sync-s and --fetch-submodules for named project sync

10 views
Skip to first unread message

Sam Liddicott

unread,
Sep 24, 2025, 6:45:02 AM (2 days ago) Sep 24
to Repo and Gerrit Discussion
I notice in command.py that if any modules are named for syncing, that repo sync will not sync git submodules if they are also explicitly named as arguments, even if --fetch-submodules is passed on the command line.

Contrast this with the no-argument behaviour that syncs all modules including submodules when `submodules_ok or project.sync_s` are true or --fetch-submodules is passed.

There is some argument that if a module is named, then so ought the submodules to be named, but this behaviour is non-obvious, and  `GetDerivedSubprojects`, `get_submodules`, and `parse_gitmodules` show just how difficult it can be for a built tool to find the names of those submodules in order to name them.

But that argument isn't even really valid in the case where --fetch-submodules is also passed on the command line (submodules_ok to the function).

And it is often an incidental detail whether or not a manifest project source uses git submodules, and in fact the submodules used may vary between branches.

If the project uses submodules, then they are needed. It's should be enough to have to add the `sync-s` tag but then to have to maintain a list of the submodules for a build tool that uses repo, just so that repo will update them (when not updating all modules)  is quite a burden.

Is there a strong reason why something like this patch shouldn't be applied to command.py so that submodules are also processed when the parent module is specified?

diff --git a/command.py b/command.py
index c32a095..0198674 100644
--- a/command.py
+++ b/command.py
@@ -464,6 +464,15 @@ class Command:
                 if not projects:
                     raise NoSuchProjectError(arg)
 
+                # get sub-projects too, even for named projects
+                derived_projects = {}
+                for project in projects:
+                    if submodules_ok or project.sync_s:
+                        derived_projects.update(
+                            (p.name, p) for p in project.GetDerivedSubprojects()
+                        )
+                projects.extend(derived_projects.values())
+
                 for project in projects:
                     if not missing_ok and not project.Exists:
                         raise NoSuchProjectError(

Without this, a repo sync (on a project that was cared about enough to be named on the command line) will be incomplete or with out of date submodules, and no warnings!

At the very least, --fetch-submodules should be respected when explicitly passed on the command line.

Is this reasonable or am I wrong?

I'll probably be maintaining this patch out-of-tree but thought it would be the decent thing to share such an obvious solution to a painful problem.

Sam
Reply all
Reply to author
Forward
0 new messages