Using git-subrepo in a JS monorepo to include another JS monorepo
horacioh opened this issue · comments
Hello!
I stumbledupon this project because I'm customizing a library inside my application.
Let's call my application "Application" and the library I'm using "Library". The issue I see is that I'm not sure how I can set this up in a way I can add my custom code on top of the Library and refer to the actual source files in the Library from my application.
Does anyone have an example of doing such a thing? Is there any recommendations I can check or need to address?
thanks!
Your use case is exactly what subrepo is designed to do. In your application root you should add the Library as a directory of your application git subrepo clone <url> <directory the source will be located in>
. This imports the source of your library into your application. You can then treat the files in the subrepo as if they are files in your project (because they are). After you have made some changes in application that may include changes to the files in the directory containing the library and you want to submit those changes to the version of the library at the URL then you would git subrepo push
. That will rebase your changes to the top of the remote library and push them upstream.
I have found ensuring that commit messages that have files from a subrepo are reviewed especially close to ensure that they make sense when you push changes to the remote. If not I have needed to use the git subrepo branch
to refine the commits so they make more sense for the consumer.
One thing that has proven painful is when you have review systems that change the SHA after commit, for instance Gerrit which puts a lot of tags on a patch when committing. git subrepo stores the SHA of the insertion point of the remote library into the local repo's tree so it can do its operations. If the SHA changes from being rewritten or rebase that is the most common source of issues when using git subrepo. I have a hook that checks to ensure that the SHA is valid in the public tree which I do not allow to be rewritten for any reason.
Hope this was helpful, and happy to answer any additional questions you may have.