I have git repo A containing submodule B. A file file.c is located inside B's folder, itself inside of A's folder as you'd expect. Question : can I track this file from A and not from B ? Does that even make any sense ?
Idea is that any user of B has to add their own file.c in this specific location of B's folder hierarchy. If someone fails to do that but still adds B as submodule, B will simply mention that there is no target file upon compiling/running.
In other words, you might have:
for (slightly silly) example. (There's also a
.gitmodules
here but it is hidden away since it is a dot-file.)The question makes sense, but the answer is a resounding No (boom, thud). The problem is the way the existence of submodule B is represented within repository A.
The current (HEAD) commit of repository A has a
tree
object that claims the existence of at least twoblob
objects:.gitmodules
: this file has in it the URL for a repository, along with apath
entry that saysB
B
: this blob has mode160000
(a "gitlink" entry). The "contents" of this blob are the commit hash ID that Git should check out, once Git has cloned the URL so thatB/
exists. Presumably, checking out that hash ID gets you a file namedfile.c
, so thatB/file.c
exists.To store the existence of a blob that would be extracted into
B/file.c
within the superprojectA
, Git would need to store a secondtree
object namedB
in the top level tree (this secondtree
object would itself have a blob namedfile.c
, which would then be extracted intoB/file.c
). But there is already a gitlinkblob
object namedB
, so it can't: a duplicate name is disallowed.What you could do is store, in submodule repository B, a symlink named
file.c
, pointing to../user-supplied-file.c
or../user/file.c
or some such. Now repository A needs to containuser-supplied-file.c
oruser/file.c
or whatever the link points to.Note that this couples the submodule rather tightly with the superproject. At this point, it might be more reasonable not to bother with a submodule at all. Libraries and other such submodule-worthy items do not typically require additional source code; they might have routines that take function pointers, and call those functions through those pointers, but they don't have entirely-external source dependencies.