I've been playing with git internals, and noticed that tree objects can store commit objects, using the ls-tree/mktree format:
0160000 commit <sha1> name
I'm wondering how the git GC handles such a situation.
The source code refers to this as a directory link
since the normally invalid mode bitmask 0160000
happens to be a combination of the directory and link bitmasks, and a gitlink
since it
is a link to another git directory.
Looking around I can see that submodule behavior is built on this (paired with a .gitmodules
file to know where the other git directory is), but would git choke on it if it found one in the wild, in some other context? What if the commit was instead a local commit within the git object database? Were this the only reference to the commit would that commit not be GC'd, or does the GC not count this as a reference since it assumes it's external?