3 ms·
I finally found a use case for git submodules: We have a git repo which provides a wrapper around compiling and packaging the Linux kernel for RISC-V, and we us
by rwmj 9y ago
I finally found a use case for git submodules: We have a git repo which provides a wrapper around compiling and packaging the Linux kernel for RISC-V, and we use a submodule to link to a specific release of Linux. (https://github.com/rwmjones/fedora-riscv-kernel https://github.com/rwmjones/fedora-riscv-kernel)
However this also reveals the awkwardness of submodules:
* Everyone who clones the git repo either forgets or doesn't know that they have to do 'git submodule init' (and maybe update too? even I'm forgetting ...). So everyone asks us on IRC why it "doesn't work" and has to be told what to do. IMO git clone should also clone the submodules and set things up.
* You cannot add downstream patches to Linux this way. For a while we needed a small bug fix which wasn't in the Linux submodule (it's controlled by another company) so we had an awkward workaround in the build system to copy the whole submodule and apply the patch before building.
* The link is to a non-fast-forward branch of Linux, so the commit hash sometimes becomes invalid, which we don't notice until someone is trying to build it from scratch. You'd think that because both the module and submodule are hosted on github, that github wouldn't garbage collect the old commit hash, but that's apparently not how it works.
I don't know if there's some tool which solves this use case better, but git submodules are what we have.
- Arnavion 9y ago>they have to do 'git submodule init' (and maybe update too? even I'm forgetting ...) `git submodule update --init --recursive` to combine init and update and also recursively.
- jononor 9y agoYour CI system should build every commit from scratch, then you detect the problem right away. And don't rewrite history on branches which other things refer to, you are destroying the ability to check out old versions. I don't understand why you cannot add your own patches though? Just need to push your fork somewhere available and then ref that in your submodule?
- jasonkeene 9y ago> * Everyone who clones the git repo either forgets or doesn't know that they have to do 'git submodule init' (and maybe update too? even I'm forgetting ...)... ‘git clone --recursive’ Add that to your README’s getting started section. Sounds a bit like you aren’t providing a good onramp for contributors. > * You cannot add downstream patches to Linux this way... > * The link is to a non-fast-forward branch of Linux, so the commit hash sometimes becomes invalid... You'd think that because both the module and submodule are hosted on github, that github wouldn't garbage collect the old commit hash, but that's apparently not how it works. Commits will not get GCed if you have a ref pointing at them. Relying on commits that do not have a ref means they are not part of the official history of that project. You should fork linux and have a branch where you land your custom changes. You can track whatever upstream you want, third party or mainline linux, and rebase your changes on top of them.