Using Git submodules
Platform.sh allows you to use submodules in your Git repository. They are usually listed in a
.gitmodules file at the root of your Git repository. When you push via Git, Platform.sh will try to clone them automatically.
Here is an example of a
[submodule "app/Oro"] path = src/Oro url = https://github.com/orocrm/platform.git [submodule "src/OroPackages/src/Oro/Bundle/EntitySerializedFieldsBundle"] path = src/OroPackages/src/Oro/Bundle/EntitySerializedFieldsBundle url = https://github.com/orocrm/OroEntitySerializedFieldsBundle.git [submodule "src/OroB2B"] path = src/OroB2B url = https://github.com/orocommerce/orocommerce.git
When you run
git push, you can see the output of the log:
Validating submodules. Updated submodule git://github.com/orocommerce/orocommerce: 4 references updated. Updated submodule git://github.com/orocrm/platform: 229 references updated. Updated submodule git://github.com/orocrm/OroEntitySerializedFieldsBundle: 11 references updated.
If you see the following error:
Validating submodules. Found unresolvable links, updating submodules. E: Error validating submodules in tree: - /src/Oro: Exception: commit 03567c6 not found. This might be due to the following errors fetching submodules: - email@example.com:orocommerce/orocommerce.git: HangupException: The remote server unexpectedly closed the connection.
Since the Platform.sh Git server cannot connect to GitHub via SSH without being granted an SSH key to do so, you should not use an SSH URL:
firstname.lastname@example.org:..., but you should use an HTTPS URL instead:
When using Git submodules that are hosted on private repositories, using the
https protocol will fail with errors like:
GitProtocolError: unexpected http resp 401 for https://bitbucket.org/myusername/mymodule.git/info/refs?service=git-upload-pack
To fix this, you need to:
.gitmodulesfile from HTTPS syntax to SSH syntax, e.g.
[submodule "support/mymodule"] path = support/mymodule url = https://bitbucket.org/myusername/mymodule.git
[submodule "support/mymodule"] path = support/mymodule email@example.com:myusername/mymodule.git
Add the public key for the project from the project settings Deploy Key tab in the Platform.sh management console (see more about private repositories), which will allow our Git service to pull the module from the remote git service. This assumes you have configured the remote git repository to allow this by generating a private/public key pair. For example, see the Bitbucket documentation.
These steps are not specific to Platform.sh, but kept as a reference for Git so that submodules are effectively removed prior to entering the build process.
Delete information for the submodule you’d like to remove from
Stage changes to
$ git add .gitmodules
Remove the submodule’s configuration from
Remove the submodule from the repository (without trailing slash):
$ git rm --cached path_to_submodule
Remove the submodule’s files in
.gitfrom the repository (without trailing slash):
$ rm -rf .git/modules/path_to_submodule
Commit the changes:
$ git commit -m "Removed submodule."
Remove the submodule code locally, now untracked:
$ rm -rf path_to_submodule
Original can be found in a gist by Mahdi Yusuf, replicated here for internal linking.