5

is there some hook script in git that will detect if the submodule source tree is available whenever you push to the main project? Intend to avoid people pushing a master project that has unpushed submodules

Zernel
  • 1,487
  • 2
  • 15
  • 27

2 Answers2

5

You can use (git 1.7.7+):

 git push --recurse-submodules=on-demand

I present it in "Git submodule push", and it detects any submodule modification, to push it first, before pushing the main repo.


Note that there are 2 options:

git push --recurse-submodules=check
git push --recurse-submodules=on-demand

Make sure all submodule commits used by the revisions to be pushed are available on a remote tracking branch.

  • If check is used git will verify that all submodule commits that changed in the revisions to be pushed are available on at least one remote of the submodule.
    If any commits are missing the push will be aborted and exit with non-zero status.

  • If on-demand is used all submodules that changed in the revisions to be pushed will be pushed.
    If on-demand was not able to push all necessary revisions it will also be aborted and exit with non-zero status.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

You can use git submodule foreach to invoke any command for each submodule, so to check whether your branch is behind origin/master, run:

git submodule foreach git status

To push all your changes from submodules, run:

git submodule foreach git push

See: man git-submodule.

kenorb
  • 155,785
  • 88
  • 678
  • 743