git submodules without .gitmodules file?
Asked Answered
N

1

3

Switching branches (using SourceTree), I get error messages like

fatal: No url found for submodule path '...' in .gitmodules

There is no .gitmodules file in the whole project.

Where should I look at?

SourceTree hits the following command upon branch switching:

git --no-optional-locks -c core.quotepath=false submodule update --init 

When I enter git submodules, the output is:

# git submodule                        
fatal: no submodule mapping found in .gitmodules for path '...'

Folder ... is empty.

Neely answered 7/1, 2020 at 17:45 Comment(5)
Does this command git submodule--helper list return any ouptut for that folder ?Brachylogy
@SaurabhPBhandari yes, 160000 39747efdc1ff781939c45f321475f00f71ef3172 0 the-folder/Neely
Based on this answer, git rm --cached the-folder/ (provided the-folder/ is the same as the folder ... mentioned in the question above) should remove the error messageBrachylogy
@SaurabhPBhandari It worked, the the-folder/ folder was not a real folder but a submodule itself i guess. I removed it and the error went away.Neely
This has more detailsBrachylogy
D
4

What you have here is a broken submodule. (Or half a submodule? A submodule without instructions? It's not clear just what to call it—other than, as VonC notes, we can say that the gitlink half is a "gitlink", which at least is a searchable jargon term.)

A submodule, in Git, is a reference to another Git repository. In order to use the submodule, you must already have the other Git repository. In general, to make a Git repository, we mostly use git clone to copy some other, existing, repository. So normally, a submodule carries along with it the necessary instructions that Git will need in order to run git clone. These instructions go into the .gitmodules file.

If the .gitmodules file is missing, as in this case, it means that the instructions for setting up the submodule are missing. It's up to you whether to repair this by adding the instructions, or to repair it by removing the badly-formed submodule from your next commit.

Removing the half-formed submodule is easier. See VonC's accepted answer to No submodule mapping found in .gitmodule for a path that's not a submodule, but all you have to do is use git rm and then commit. This new commit will no longer refer to the submodule that cannot be cloned because the cloning instructions are missing. Subsequent new commits, built from this commit that doesn't mention the submodule, also won't mention the submodule (which continues to not exist).

Note that all existing commits remain broken. The only thing you can do about this is to remove (or replace) any existing broken commits, because no existing commit can be modified. It's generally not a great idea to try to fix or remove existing commits, as other people may be depending on them. A half-submodule / broken-submodule like this can be worked-with as a regular (non-broken) submodule if you have the other Git repository cloned into place.

To fix the problem by fixing the submodule, put the appropriate configuration into a new .gitmodules file and git add and git commit the .gitmodules file. The problem with actually doing this, of course, is that you need to know what the instructions are. Some of them are clear from the broken submodule, because the information in the .gitmodules file comes in several parts: one part is the path, which is just the name of the mode-160000 git ls-files entry (again, see VonC's answer). But the other part is the URL for the repository that should be cloned, and who knows what that might be?1


1In theory, whoever owns whichever repository you cloned to get into this situation should know—or, they should know who knows, or know someone who knows someone who knows, etc. But in practice, you get a lot of It was like that when I got here.

Daryn answered 7/1, 2020 at 19:16 Comment(6)
Regarding your footnote: I'm working by the rule of origin/master precedence. Whats not working in that branch, will not be missed anywhere.Neely
It is clear what to call it: a nested Git repository stored as a gitlink tree entry, as explained git-scm.com/docs/gitsubmodules.Macdonald
@VonC: but that calls out four forms of submodule, all of which have a .gitmodules file. In this case there is a gitlink but no .gitmodules file. What is the correct name for this fifth form? (Note that the OP has no second Git repository either, just an empty folder where Git expects to find something.)Daryn
@Daryn I meant: a nested git repo without a .gitmodule is just a gitlink (a special entry in the index).Macdonald
When I removed the empty folder, the message in git history was this: Deleted file: Subproject commit 39747efdc1ff781939c45f321475f00f71ef3172. All what you both point out makes sense.Neely
so @torek, "put the appropriate configuration into a new .gitmodules file and git add and git commit the .gitmodules file" suggests that git submodules looks at the checked in version instead of the edited version? Highly irregular behavior, 'persistence' like this is not expected.Ylem

© 2022 - 2024 — McMap. All rights reserved.