Skip to content

No way to specify which git submodules to clone into in project config

Sometimes we don't want to clone every submodule in a git repo. In particular, the Qt framework seems to include private submodules. The below patch allows us to pass in a list of submodules to the git_submodule project parameter. For my particular use case, my project config changes from git_submodule: 1 to

git_submodule: 'qtbase qtdeclarative qtimageformats qtquickcontrols qttools qttranslations qtwinextras qtmultimedia'

If the value of git_submodule is 1, then all of the submodules are still cloned the same way as without the patch.

Proposed patch:

diff --git a/lib/RBM.pm b/lib/RBM.pm
index b9ad1ad..063b8fc 100644
--- a/lib/RBM.pm
+++ b/lib/RBM.pm
@@ -392,18 +392,32 @@ sub git_clone_fetch_chdir {
                                 'git_clone_dir', $options)));
     my $git_url = project_config($project, 'git_url', $options)
                 || exit_error "git_url is undefined";
-    my @clone_submod = ();
     my @fetch_submod = ();
-    if (project_config($project, 'git_submodule', $options)) {
-        @clone_submod = ('--recurse-submodules');
+
+    my $git_submodule = project_config($project, 'git_submodule', $options);
+    if ($git_submodule) {
         @fetch_submod = ('--recurse-submodules=on-demand');
     }
     if (!chdir rbm_path("$clonedir/$project")) {
         chdir $clonedir || exit_error "Can't enter directory $clonedir: $!";
-        if (system('git', 'clone', @clone_submod, $git_url, $project) != 0) {
+        if (system('git', 'clone', $git_url, $project) != 0) {
             exit_error "Error cloning $git_url";
         }
         chdir($project) || exit_error "Error entering $project directory";
+        if ($git_submodule) {
+            if ($git_submodule eq '1') {
+                if (system('git', 'submodule', 'update', '--init', '--recursive') != 0) {
+                    exit_error "Error initing $git_url submodules";
+                }
+            } else {
+                my @submodule_list = split ' ', $git_submodule;
+                foreach my $sm (@submodule_list) {
+                    if (system('git', 'submodule', 'update', '--init', "$sm") != 0) {
+                        exit_error "Error initing $project submodule $sm";
+                    }
+                }
+            }
+        }
     }
     if (git_need_fetch($project, $options)) {
         system('git', 'remote', 'set-url', 'origin', $git_url) == 0
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information