Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git push --recurse-submodules=on-demand is not truly recursive

I have the following project structure:

root-project
      |
      |-- A
      |   |
      |   |-- C
      |
      |-- B

A and B are submodules of the root-project. C is in turn a submodule of project A. Suppose I have made changes to projects A,B and C and commited these changes to the respective indices. After that I update the references to A and B in the root-project and commit that change as well. When I push the changes of the root-project with the option --recurse-submodules=on-demand, git pushes all commits of projects A, B and the root-project, but silently ignores the commits of project C. I would expect that it pushes the changes of project C as well.

I know that i can work around this problem by using the following two commands in the root-project folder.

git submodule foreach --recursive 'git push origin master'
git push

Could someone clarify whether I'm doing something wrong or if this is a bug in git-push.I have already asked this question on the git mailing list but didn't receive any response: http://thread.gmane.org/gmane.comp.version-control.git/266184

I have also written a small shell script that sets up the described project structure and executes the recursive push operation: https://gist.github.com/usommerl/6e8defcba94bd4ba1438

git version 2.3.3

like image 634
Uwe Sommerlatt Avatar asked Apr 10 '15 14:04

Uwe Sommerlatt


1 Answers

git push --recurse-submodules=on-demand will be truly recursive with git 2.14.x/2.15 (Q3 2017), but with some condition.

See commit c7be720 (20 Jul 2017) by Brandon Williams (mbrandonw).
(Merged by Junio C Hamano -- gitster -- in commit a49794d, 22 Aug 2017)

submodule--helper: teach push-check to handle HEAD

In 06bf4ad (push: propagate remote and refspec with --recurse-submodules, git 2.13.0) push was taught how to propagate a refspec down to submodules when the '--recurse-submodules' flag is given.

The only refspecs that are allowed to be propagated are ones which name a ref which exists in both the superproject and the submodule, with the caveat that 'HEAD' was disallowed.

This patch teaches push-check (the submodule helper which determines if a refspec can be propagated to a submodule) to permit propagating 'HEAD' if and only if:

  • the superproject and the submodule both have the same named branch checked out and
  • the submodule is not in a detached head state.
like image 120
VonC Avatar answered Oct 24 '22 10:10

VonC