1

I'm sure you know the situation but I don't know the correct wording:

I have a repository with a couple of submodules which I work on in the context of the main repository - i.e. I often have to change the content of the submodules rather than working on them somewhere else separately.

When I've added/committed changes to those submodules, quite often I commit/push the submodules new commit ID but forget to push the submodule itself.

Locally this is no problem and hard to identify but of course the build breaks because even the checkout goes wrong.

I know with git this situation is not easy to handle in a general way because of how remotes work but there must be approaches to avoid this situation.

What is yours? Is there a git intrinsic method?

frans
  • 8,868
  • 11
  • 58
  • 132
  • Probably not the smartest but I almost always only add the changes that I want to commit to the staging area. – josephting Mar 11 '19 at 07:51
  • 1
    Pre-commit or pre-receive hooks: https://github.com/rodrigo-lima/submodule_checker – 1615903 Mar 11 '19 at 07:56
  • 1
    Pre-receive hook would hardly help — it's a server-side hook. Pre-commit hook with something like `git submodule foreach git push` is the way to go; `git push` on an updated submodule is a no-op. – phd Mar 11 '19 at 12:10
  • 1
    @phd `pre-receive` hook could defiinitely help, if OP has authority to install `pre-receive` hooks in the remote repo, a `pre-receive` hook could reject all users from pushing a commit referencing a submodule commit which does not exist in the remote. – Alderath Mar 11 '19 at 12:49
  • @Alderath Pushable remote is usually a bare repository, it doesn't contain working directory and submodules. How does a server-side hook in this situation check if submodules have been updated? – phd Mar 11 '19 at 15:16

1 Answers1

2

You have various local configurations to make a simple git push to also include the submodules (meaning you are pushing the submodules and your main project, all in one go)

git config push.recurseSubmodules on-demand
git push
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250