mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [BUG] Recursive submodules fails to track branch correctly if . is used
       [not found] <>
@ 2019-07-16 21:49 ` Krzysztof Opasiak
  0 siblings, 0 replies; only message in thread
From: Krzysztof Opasiak @ 2019-07-16 21:49 UTC (permalink / raw)
  To: git; +Cc: cedric.ollivier, DEBEAU Eric IMT/OLN

Dear git community,

I'd like to report you a potential bug in git submodule implementation.

* Problem statement

According to doc a special value of "." can be used as a branch name to 
track. This means that git should trace the same branch as is currently 
in use in superproject. This works perfectly fine as long as you don't 
try to add superproject (SUP1) with such configuration as a submodule to 
another superproject (SUP2). The nesting structure would look like this:

     - SUP1
         - SUB_PROJECT

If you try to do this you won't be able to execute any of the following 

$ git clone --recursive SUP2

$ git clone SUP2 & git submodule update --init --recursive --remote

$ git submodule update --init --recursive --remote

as every time you will get an error message similar to this one:

fatal: Submodule (SUB_PROJECT) branch configured to inherit branch from 
superproject, but the superproject is not on any branch
fatal: Needed a single revision
Unable to find current origin/ revision in submodule path 'SUB_PROJECT'

* Initial investigation results

The error message comes from remote_submodule_branch():1938 in 
submodule--helper.c and it is generated called from SUP1 dir (due to 
--recursive flag). Actually this function behaves correctly. If you go 
to SUP1 dir and check the branch info you will notice that the repo is 
in detached head state.

* Probable root cause

The root cause is that the traced branch information is never propagated 
to the submodules. All the submodules are always initialized in a 
detached head state and there is no way to change this behavior nor to 
propagate the traced branch information to submodules.

* Workaround script

I managed to workaround this bug by dropping the recursive option and 
after the top level project has been cloned I go through every 
submodule, set local branch to point to current head and then just do 
git checkout and I do this recursively in all modules. After this I'm 
able to successfully execute:

$ git submodule update --rebase --recursive --remote

The script (to be executed in SUP2 right after clone):


function prepare_submodules {
	git submodule update --init
	local SUBMODULE_LIST=`git submodule--helper status | awk '{print $2}'`
	while read -r submod; do
		local PARENT_DIR=`pwd`
		local BRANCH=`git submodule--helper remote-branch ${submod}`

		cd ${submod}
		git branch -f ${BRANCH} HEAD;
		git checkout ${BRANCH}
		if [ ! -z "`git submodule status`" ]; then
		cd ${PARENT_DIR}
	done <<< "$SUBMODULE_LIST"


Best regards,
Krzysztof Opasiak
Samsung R&D Institute Poland
Samsung Electronics

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-07-16 21:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <>
2019-07-16 21:49 ` [BUG] Recursive submodules fails to track branch correctly if . is used Krzysztof Opasiak

Code repositories for project(s) associated with this public inbox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).