زیر ماژول ‌ها

بررسی اجمالی

A Git submodule allows you to integrate other Git projects into your code, without the need to copy-paste all their code.

Indeed, your custom modules can depend on modules from other repositories. Regarding Odoo, this feature allows you to add modules from other Git repositories into the branches of your repository. Adding these dependencies in your branch through submodules makes the deployment of your code and servers easier, as you can clone the repositories added as submodules at the same time you clone your own repository.

Besides, you can choose the branch of the repository added as submodule and you have the control of the revision you want. It's up to you to decide whether you want to pin the submodule to a specific revision and when you want to update to a newer revision.

In Odoo.sh, the submodules give you the possibility to use and depend on modules available in other repositories. The platform will detect that you added modules through submodules in your branches and add them to your addons path automatically so you can install them in your databases.

If you add private repositories as submodules in your branches, you need to configure a deploy key in your Odoo.sh project settings and in your repository settings. Otherwise Odoo.sh won't be allowed to download them. The procedure is detailed in the chapter Settings > Submodules.

افزودن یک زیر ماژول

با Odoo.sh (ساده)

هشدار

For now it is not possible to add private repositories with this method. You can nevertheless do so with Git.

On Odoo.sh, in the branches view of your project, choose the branch in which you want to add a submodule.

In the upper right corner, click on the Submodule button, and then on Run.

../../../_images/advanced-submodules-button.png

A dialog with a form is shown. Fill the inputs as follows:

  • Repository URL: آدرس SSH مخزن.

  • Branch: شاخه‌ای که می خواهید استفاده کنید.

  • Path: پوشه ای که می خواهید این زیر ماژول را در شاخه خود اضافه کنید.

../../../_images/advanced-submodules-dialog.png

On Github, you can get the repository URL with the Clone or download button of the repository. Make sure to use SSH.

../../../_images/advanced-submodules-github-sshurl.png

با گیت (پیشرفته)

In a terminal, in the folder where your Git repository is cloned, checkout the branch in which you want to add a submodule:

$ git checkout <branch>

سپس، زیر ماژول را با استفاده از دستور زیر اضافه کنید:

$ git submodule add -b <branch> <git@yourprovider.com>:<username/repository.git> <path>

جایگزین کنید

  • <git@yourprovider.com>:<username/repository.git> by the SSH URL of the repository you want to add as submodule,

  • <branch> توسط شاخه‌ای که می خواهید در مخزن بالا استفاده کنید،

  • <path> توسط پوشه ای که می خواهید این زیر ماژول را در آن اضافه کنید.

تغییرات خود را متعهد و فشار دهید:

$ git commit -a && git push -u <remote> <branch>

جایگزین کنید

  • <remote> by the repository on which you want to push your changes. For a standard Git setup, this is origin.

  • <branch> by the branch on which you want to push your changes. Most likely the branch you used git checkout on in the first step.

You can read the git-scm.com documentation for more details about the Git submodules. For instance, if you would like to update your submodules to have their latest revision, you can follow the chapter Pulling in Upstream changes.

ماژول ‌ها را نادیده بگیرید

If you're adding a repository that contains a lot of modules, you may want to ignore some of them in case there are any that are installed automatically. To do so, you can prefix your submodule folder with a .. The platform will ignore this folder and you can hand pick your modules by creating symlinks to them from another folder.