Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Utilities to manage git submodules #8

Open
jacintoArias opened this issue Apr 7, 2018 · 0 comments
Open

Utilities to manage git submodules #8

jacintoArias opened this issue Apr 7, 2018 · 0 comments

Comments

@jacintoArias
Copy link
Member

When using git submodules inside a monorepo one must take care of the following steps manually:

Initiating git submodules (when cloning new project)

Cloning the repo with --recurse-submodules or performing git submodule update --init or git submodule init; git submodule update. This could be tackled with something like demorepo update or something like that.

Updating git submodules (when changes have been made to upstream)

One must invoke git submodule update --remote, perhaps we can just use the previous command demorepo update, probably we always want the latest upstream version.

Tracking particular branches of submodules in demorepo parent branches

When tracking a particular branch of the subproject one must update git config and .gitmodules references with git config -f .gitmodules submodule.<projectName>.branch <branchname>.

This could be automated by something like demorepo project --branch develop. However reflecting the changes on the config is tricky, all options have pros and cons:

  • Reflect particular branch of submodule on config.yml. Dangerous as merging between parent demorepo branches would result in ovrewriting this info.

  • Ignoring tracked branch on demorepo and just rely on .gitmodules file to track the branches (this file is not merged between branches).

  • Reflect particular changes in config.yml by project and branch:

projects: [
  {
    "path": "proj1", 
    "branches": {
      "master": "master",
      "develop": "develop"
    }
  }
]

This would be nice, as we could event default common patters as creating default gitflow branches.

Switching branches

When switching branches one should invoke git submodule update --remote to fetch the correct commit for the submodules, otherwise changes could be commited. One can also use git checkout <branch> --resource-submodules to automatically change to the correct commit.

Demorepo could just provide a particular checkout command enforcing this, or perhaps this behaviur can be ensured into git config

https://git-scm.com/docs/git-config

Another option could be to create a git hook to do ensure this or to launch a warning.

Another issue is that is a branch is tracking a submodule and another one isn't (eg: you added a new project to develop but it does not yet exists in master), and you checkout between them the untracked submodule would appear as an untracked directory.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant