git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: gitconfig get out of sync with submodule entries on branch switch

From
BWBrandon Williams <bmwill@google.com>
Date
Jan 30, 2017, 17:51 UTC
Message-ID
<20170130175118.GA35626@google.com>
In-Reply-To
<0f14df64-1aa2-e671-9785-4e5e0a076ae6@gmail.com>
On 01/30, Benjamin Schindler wrote:
Show 30 quoted lines
> Hi
> 
> Consider the following usecase: I have the master branch where I
> have a submodule A. I create a branch where I rename the submodule
> to be in the directory B. After doing all of this, everything looks
> good.
> Now, I switch back to master. The first oddity is, that it fails to
> remove the folder B because there are still files in there:
> 
> bschindler@metis ~/Projects/submodule_test (testbranch) $ git
> checkout master
> warning: unable to rmdir other_submodule: Directory not empty
> Switched to branch 'master'
> 
> Git submodule deinit on B fails because the submodule is not known
> to git anymore (after all, the folder B exists only in the other
> branch). I can easily just remove the folder B from disk and
> initialize the submodule A again, so all seems good.
> 
> However, what is not good is that the submodule b is still known in
> .git/config. This is in particular a problem for us, because I know
> a number of tools which use git config to retrieve the submodule
> list. Is it therefore a bug that upon branch switch, the submodule
> gets deregistered, but its entry in .git/config remains?
> 
> thanks a lot
> Benjamin Schindler
> 
> P.s. I did not subscribe to the mailing list, please add me at least
> do CC. Thanks

submodules and checkout don't really play nicely with each other at the moment. Stefan (cc'd) is currently working on a patch series to improve the behavior of checkout with submodules. Currently, if you want to ensure you have a good working state after a checkout you should run `git submodule update` to update all of the submoules. As far as your submodule still being listed in the config, that should be expected given the scenario you described.

If I'm understanding you correctly, A and B are both the same submodule just renamed on a different branch. The moment you add a submoule to a repository it is given a name which is fixed. Typically this is the path from the root of the repository. The thing is, since you are able to freely move a submodule, its path can change. To account for this there is the .gitmodules file which allows you to do a lookup from submodule name to the path at which it exists (or vice versa). The submodules that are stored in .git/config are those which are 'initialize' or rather the submodules in which you are interested in and will be updated by `git submodule update`. So given your scenario you should only have a single submodule in .git/config and the .gitmodules file should have a single entry with a differing path for each branch.

Hopefully this gives you a bit more information to work with. Since Stefan has been working with this more recently than me he may have some more input.

-- 
Brandon Williams
Previous: Benjamin SchindlerNext: Benjamin Schindler
Message 2 of 7 in “gitconfig get out of sync with submodule entries on branch switch”
  1. Benjamin SchindlerJan 30, 2017
  2. Brandon WilliamsJan 30, 2017
  3. Benjamin SchindlerJan 31, 2017
  4. Stefan BellerJan 31, 2017
  5. Stefan BellerFeb 6, 2017
  6. Benjamin SchindlerFeb 6, 2017
  7. Stefan BellerFeb 8, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.