Source code management mode of oneos Lite – sub module management

Time:2021-10-25

preface

Simple and clear code structure is conducive to project code management.OneOS-Liteusegit submoduleTo manage the code.

Among them,OneOS-LiteThe warehouse is the primary repository. And kernelkernel, and componentscomponentsAnd drivedriversWill be in the form and form of sub modulesOneOS-LiteMaster warehouse association management.

Retrieval sub module

This commandgit submoduleYou can view the existing sub modules or sub warehouses in the main warehouse.

$ git submodule
-ba2c4170016ff14db298c5e87134704996c5aff5 thirdparty/cJSON
-e99c7b71349f74804eb215c59fa426bf5a357d8f thirdparty/telnetd

Take the above example:

  • -It means that the source code file of the sub module warehouse has not been checked in (empty folder), and there is no-The representative has checked in;
  • e99c7b71349f74804eb215c59fa426bf5a357d8fRepresents the sub module components andOneOS-LiteAssociated version ID;
  • thirdparty/telnetdRepresents the directory corresponding to the sub module warehouse and its component name.

Get sub module

usegit cloneThe source code files of the sub module warehouse will not be checked in, but the empty folder of the corresponding sub module components will be pulled down. At this time, if you need to use a sub module component, you can use the following command:

git submodule init
Git submodule update XXX (sub module component name, you can view the existing contribution components through git submodule)

For example, chestnuts:

$ git submodule init
Submodule 'thirdparty/cJSON' ([email protected]:luoshunyuan/cJSON.git) registered for path 'thirdparty/cJSON'
Submodule 'thirdparty/telnetd' ([email protected]:luoshunyuan/telnetd.git) registered for path 'thirdparty/telnetd'
$ git submodule update thirdparty/telnetd
Cloning into 'D:/xiaoneng/oneos-2.0-test/thirdparty/telnetd'...
Authorized users only. All activity may be monitored and reported.
Submodule path 'thirdparty/telnetd': checked out 'e99c7b71349f74804eb215c59fa426bf5a357d8f'

If you need to obtain all sub module warehouses, you can use them directlygit submodule update

Associated sub module

Through a in the root directory of the project.gitmodulesFile, you can find the associated sub warehouse. Each time you add a sub module warehouse, a new record will be added. The contents are as follows:

[submodule "thirdparty/telnetd"]
    path = thirdparty/telnetd
    url = [email protected]:luoshunyuan/telnetd.git
[submodule "thirdparty/cJSON"]
    path = cJSON
    url = [email protected]:luoshunyuan/cJSON.git

To continue associating new sub modules, you can use the followinggitCommand, heretelnetdFor example:

git submodule add [email protected]:luoshunyuan/telnetd.git thirdparty/telnetd

If you need to change the sub warehouse, you can open it in the corresponding sub warehouse directory firstgitFrom the command line, enter the GIT warehouse management of the corresponding contributing component, and execute the code submission operation:

Source code management mode of oneos Lite - sub module management

Because the sub module warehouse code is modified and submitted, but the pointer of the main warehouse still points to the old sub warehousecommit id, if you don’t submit this modification, someone else will pull the main project and use itgit submodule updateThe updated sub module will still pull the code before modification.

Therefore, the main project needs to be submitted and updated at this time.

Source code management mode of oneos Lite - sub module management

Delete obsolete components

When some sub warehouses are no longer needed and need to be discarded and deleted,gitThere is no command to delete sub modules directly, so you can only delete related files step by step:

  1. To delete a sub module in version control:

    git rm -r thirdparty/cJSON

  2. Delete in editor.gitmodulesRelevant contents:

    [submodule "thirdparty/cJSON"]
        path = thirdparty/cJSON
        url = [email protected]:luoshunyuan/cJSON.git
  3. Delete in editor.git/configRelevant contents:

    [submodule "thirdparty/cJSON"]
        url = [email protected]:luoshunyuan/cJSON.git
        active = true
  4. delete.gitCache module under:

    rm -rf .git/modules/thirdparty/cJSON
  5. Submit modification:

    git commit -am "delete submodule"
    git push

Follow & & contact

gitee: https://gitee.com/cmcc-oneos/OneOS-Lite

docs: https://oneos-lite.com/

Official account:CMCC-OneOS