Subject: Re: Auto update submodules after merge and reset

From: Jens Lehmann <[email-masked]>
Date: Tue, 13 Dec 2011 22:44:19 +0100

Am 13.12.2011 10:45, schrieb Andreas T.Auer:
> On 12.12.2011 23:39 Jens Lehmann wrote:
>>  Am 11.12.2011 22:15, schrieb Andreas T.Auer:
>> > The other use case wants to follow the commits of that other
>> > submodule without checking the corresponding gitlinks into the
>> > superproject. But wouldn't it also make sense here to define
>> > actually a mapping in the .gitmodule that says "if the branch
>> > 'develop' is checkedout in the supermodule then with every
>> > submodule update automatically pull the newest 'unstable' commit
>> > from the submodule"? Or for "master" follow "stable" or for the
>> > "maint" branch follow updates in the "bugfixes" branch.
>> >
>> > For example
>> >
>> > [submodule "commonlib"] update = heads develop:unstable
>> > master:stable maint:bugfixes
>>
>>  Having that configured with "branch=unstable", "branch=stable" etc.
>>  in .gitmodules on the superprojects branches would be simpler and
>>  achieve the same functionality.
> 
> Yes, this has been my first thought also, but there is also a good point to keep the .gitmodules stable, or you always have to change the file when branches change their names. So when the maint branch of version 1.3 become an archive branch and the new maint is on 1.4, which was the master before then you have to change the .gitmodules on these branches. I.e. .gitmodules of 1.4 have "stable" and must have "bugfixes" now and .gitmodules of 1.3 has "bugfixes" and must remove the floating completely. I'm not sure that this can always be solved with "easy" merging and therefore it is probably not really simpler, when you have to do this for every new release. Or what do you think?

I never rename branches, so I do not concur ;-) And I think the
.gitmodules file could benefit from a special merge driver being
aware of the format and some subtleties (like not just adding a
"branch" setting but rather creating a merge conflict) anyways.
So I'd prefer to keep it simple and just use the .gitmodules we
already have which can be different in different branches.

>> > So whenever a defined branch is checked out in the superproject
>> > the mapped branch will be checked out in the submodule ("new"
>> > commit), but if a (e.g. tagged) commit is checked out ("old"
>> > commit) then the gitlink in the superproject is used to check out
>> > the referenced commit in the submodule.
>>
>>  I think checkout should only use the submodule commit recorded in the
>>  superproject and a subsequent "git submodule update" should be needed
>>  to update the submodule to tip. Otherwise you record SHA-1 but still
>>  won't be able to bisect ...
> 
> bisect would leave the branch and therefore uses the recorded SHA1 for the submodule checkout instead of the tip. "follow-the-tip" should only work if the superproject follows the tip.

If you follow a tip there won't be any new SHA-1s recorded during
that following so you could not do a bisect and expect the submodule
to be what the developer had when doing the commits, no?

> If you configure auto-update on checkout you would not expect that a separate git submodule update has a different behavior.

Sure you do, when auto-update on checkout is active "git submodule update"
becomes a no-op for the exact submodule model, as "git checkout" will do
all the work "git submodule update" did before.

>> > In http://thread.gmane.org/gmane.comp.version-control.git/183837
>> > was discussed whether the gitlink in the superproject should be
>> > set to all-zero if updates follow the tip or maybe use the SHA1 of
>> > the commit when the submodule was added. I think the gitlink should
>> > be updated everytime when a new commit in the superproject is
>> > created.
>>
>>  Nope, only when "git submodule update" is run. Otherwise you'll
>>  spray the history with submodule updates totally unrelated to the
>>  commits in the superproject, which is rather confusing.
> 
> Of course, committing a new version to the superproject should not trigger pulling in a new version for the submodule or an automatic jump to the tip of the submodule. I just meant a normal manual "commit -a" behavior. Putting a 0{40} hash in the gitlink or only the hash of the submodule, when it first was added would be a special treatment that is neither needed nor wanted.

I don't get that, what SHA-1 do you want to put into the gitlink?
I understand that floating is not about updating the SHA-1 for the
submodule each commit, right?