Search code examples
gitcontinuous-integrationgit-submodulesgithookstooling

Tooling to Automatically Update Git Repositories When Their Submodule's or Submodules' Upstream Source's or Sources' Contents Change?


     What tooling exists that is designed to make it easy (or at least easier) to update a Git repository and its submodule metadata when the source or sources for any submodules contained in that parent repository changes upstream? I've seen advice that suggests using Git hooks or continuous integration and deployment systems to manage things like this in such a manner, but nobody seems to have come up with and fully explained a comprehensive solution for it that just works.


Solution

  • It depends first how the main parent repository is referencing its submodules.
    If it has submodules tracking a branch, then a simple command is enough to update a parent repo with new submodule content:

    git submodule update --recursive --remote
    

    All you then need to do is execute that regularly (cron job, Jenkins job, ...) and you main repository will always be up to date.


    could CI/CD see that a submodule the repository with which it's associated depends on has changed and run this for you if it can?

    A job could:

    • get the SHA1 of the gitlink associated to a submodule

      git rev-parse released-1.2.3^{commit}:foo
      
    • perform the update of all submodules

      git submodule update --recursive --remote
      
    • compare the SHA1 of the submodule to the original one: if there is any change, the submodule no longer reference the same SHA1 and has had some changes.