Re: Checking Out Branches Containing Submodules With update=none and submodule.recurse=true Fails With fatal:not a git repository

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Daniel, 

> Le 25 mars 2020 à 00:19, daniel mclean <maczor@xxxxxxxxx> a écrit :
> 
> Hello git developers,
> 
> Firstly thanks for a great tool!
> 
> I have run into an issue that it would be good to get your advice on.
> 
> I have a git repository with multiple submodules.  A few of these
> submodules are configured with update=none so that they point to a
> specific commit but so that clone operations and submodule update
> operations don't retrieve their contents.
> 
> When working with this repository and trying to change branches, git
> is reporting a fatal error when changing branches.  This can be worked
> around by deinit'ing the submodules before switching branches but that
> doesn't seem like it should be necessary.
> 
> The reproduction steps are to:
> - Clone the repo
> - Checkout a branch containing submodules that are set with
> update=none (git checkout branch-name)
> - Update and init submodules (git submodule update --init)
> - Attempt to switch to a different branch (git checkout other-branch)
> 
> At this point git will report an error at the first submodule with update=none:
> fatal: not a git repository: ../.git/modules/no-update-submodule
> fatal: could not reset submodule index

I tried reproducing this with the following script, but it does not fail for me:

```
!/bin/bash

set -x

create_repo () {
name=$1
rm -rf $name
git init $name
cd $name
date>>file
git add file
git commit -m "add file"
cd ../ 
}


create_repo super
create_repo sub1
create_repo sub2

cd super
git submodule add ../sub1
git submodule add ../sub2
git config -f .gitmodules submodule.sub1.update none
git add .gitmodules
git commit -m "add sub1 and sub2"
git co -b other-branch
date>>file
git add file
git commit -m "update file"
git checkout master
cd ../ 

rm -rf clone
git clone super clone
cd clone
git submodule update --init
git config submodule.recurse true
git checkout other-branch
# no error !
ls -R
```

If you could try to come up with a similar reproducer, it would help to better 
diagnose this failure. I was not sure by reading your message if both branches
involved had the same number of submodules, or the same 'update' settings
for each submodules, so maybe that's where your use case differs from my script.

> After doing some sleuthing it seems that this is because when
> update=none the submodule repository is not cloned to
> .git/module/<module name>,

I gather that's the expected behaviour, no ?

> however when attempting to change branches
> using a checkout, git then stumbles since it expects the repository to
> be there.

I've seen that happen when going from a commit where the submodule
does not exist to a commit where it does exist, (see [1], [2]), but your situation
is a little different.

> If my understanding of how update=none for a submodule and git is
> correct, then it seems like it shouldn't be trying to do this since it
> should know that the repository isn't there (update=none after all).
> This behaviour occurs when I have submodule.recurse set to true,
> however interestingly when I set it to false I don't run into this
> issue.
> So it seems like these two directives are providing mixed messages in
> a sense, one says don't clone the submodule repo and the other says
> look into the submodule repo and try to find more submodules.

>From reading the documentation of `submodule.<name>.update` [3], it seems
that `git checkout` should not care about this config setting, but in my script above,
it seems it does (at least for the value "none"), or else it would crash as you describe...
I've not looked at the code in depth, but I might if you can come up with a reproducer.

Cheers,

Philippe.

[1] https://lore.kernel.org/git/CAE5ih78zCR0ZdHAjoxguUb3Y6KFkZcoxJjhS7rkbtZpr+d1n=g@xxxxxxxxxxxxxx/
[2] https://lore.kernel.org/git/20200501005432.h62dnpkx7feb7rto@xxxxxxxxxxxx/T/#u
[3] https://git-scm.com/docs/git-config#Documentation/git-config.txt-submoduleltnamegtupdate





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux