So I have a new GitHub repository in which my Laravel app lives.
Got this set up and working fine.
I wish to create a package for the app (and plan to make use of this in other projects) and therefore I've created a workbench using artisan.
I've also added another GitHub repository for said package to live in.
I've added /workbench
to .gitignore
so that my package development doesn't get committed to the Laravel app repo.
My question is, how do I set up git so that the package in workbench is tracked only by the repo that I've set up purely for the package?
This is a question with a very big answer. In short though, you don't need submodules. Just navigate to your package's directory in workbench
and do a git init
, that'll set a git repository up there for messing with code and pushing. If workbench
is in your main app's .gitignore
then the two shouldn't get in each other's way.
However, I found that developing on something within workbench didn't work out too well. First off, when your app is in 'workbench' mode the set up is very slightly different from normal. You'll probably not really notice this, but one large difference is that any packages that your package relies on in its composer.json
actually override your main app's packages. I learned this the confusing and hard way when developing two packages (of which one relied on the other) in the same workbench app. The package that the second package relied upon wasn't actually being executed, as Laravel was seeing the files for it in the vendor
directory of the second class. Very weird and hard to debug. Anyway, it's unlikely you'll have that exact problem, but it just goes to show that Laravel is in a different 'mode' when you're using the workbench.
Also it makes teamwork a little harder - it's kinda more sensible (though I guess not necessarily easier) to use a development package in composer rather than clone a git repo into workbench. I suppose this could be a case where submodules work for you. That said I've been stung by submodules in the past and refuse to go anywhere near them again, but maybe I'm being irrational there!
So my solution is to do this:
vendor
directoryPoints/caveats:
vendor
other than when first installed or updated with composer update
, though I'm not 100% on that. Still, use PSR autoloading and it's all good.composer update
, as composer will not recognise these changes. This could be changes to dependencies, autoloading rules or anything else that you will need to rely on with your app.Bonus for teamwork is that everyone can do the same. composer require vendor/package dev-master
will get them a git repository in their vendor/vendor/package/
directory.
This is all based on my personal experience though. Supposedly there's nothing wrong with the workbench and/or submodules, but I've had issues with both in the past, so I've given up on them. I don't really think there's one right way to do this.
It seems as though after more research, git submodules are my answer!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With