Git submodule support for Adobe repositories git-submodule-support

Git submodules can be used to merge the content of multiple branches across Git repositories at build time.

When Cloud Manager’s build process runs, it first clones the pipeline’s repository and checks out the configured branch. If the branch contains a .gitmodules file in the root directory, the command is then executed.

$ git submodule update --init

This process checks out each submodule into the appropriate directory. This technique is a potential alternative to working with multiple source Git repositories for organizations that are comfortable using Git submodules and do not want to manage an external merging process.

For example, let’s say there are three repositories, each containing a single branch named main. In the “primary” repository, that is, the one configured in the pipelines, the main branch has a pom.xml file declaring the projects contained in the other two repositories:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>customer.group.id</groupId>
    <artifactId>customer-reactor</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>

    <modules>
        <module>project-a</module>
        <module>project-b</module>
    </modules>

</project>

You then add submodules for the other two repositories:

$ git submodule add -b main https://git.cloudmanager.adobe.com/ProgramName/projectA/ project-a
$ git submodule add -b main https://git.cloudmanager.adobe.com/ProgramName/projectB/ project-b

The results in the .gitmodules file look like the following:

[submodule "project-a"]
    path = project-a
    url = https://git.cloudmanager.adobe.com/ProgramName/projectA/
    branch = main
[submodule "project-b"]
    path = project-b
    url = https://git.cloudmanager.adobe.com/ProgramName/projectB/
    branch = main

See the Git reference manual for more information on Git submodules.

Limitations limitations

When using Git submodules, be aware of the following:

  • The Git URL must be exactly in the syntax described above.
  • For security reasons, do not embed credentials in these URLs.
  • Only submodules at the root of the branch are supported.
  • Git submodule references are stored to specific Git commits. As a result, when changes to the submodule repository are made, the commit referenced needs to be updated. For example, by using git submodule update --remote.
  • Unless otherwise necessary, Adobe recommends that you use “shallow” submodules by running git config -f .gitmodules submodule.<submodule path>.shallow true for each submodule.

Git submodule support for private repositories private-repositories

Support for Git submodules when using private repositories is largely the same as when using Adobe repositories.

However, after setting up your pom.xml file and running the git submodule commands, you must add a .gitmodules file to the root directory of the aggregator repository for Cloud Manager to detect the submodule setup.

.gitmodules file

Aggregator

Limitations and recommendations limitations-recommendations-private-repos

When using Git submodules with private repositories, be aware of the following limitations.

  • The Git URLs for the submodules can either be in the HTTPS or SSH format, but they must link to a Github.com repository. Adding an Adobe repository submodule to a GitHub aggregator repository or vice versa does not work.
  • The GitHub submodules must be accessible to the Adobe GitHub App.
  • The limitations of using Git submodules with Adobe-managed repositories also apply.
recommendation-more-help
c6cdc82b-cee9-48e0-a6ee-48149d5e72c3