How to use git in vendor folder of fork? - laravel

I always use composer packages in Laravel but I never changed one. This is my first time and I don't want to do it incorrect.
I need to use and change a packages foo/bar. Everything that follows now is just guessed:
I forked the repo
I created a develop branch
I added a vcs to my composer.json
"require": {
//...
"foo/bar": "dev-develop",
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/thisisme/bar"
}
],
composer update
Now I have the thisisme/bar fork in my vendor folder in foo.
So far so good. Now I can use my own fork.
But currently, as I don't know what is good practice to modify the repo, I cloned the repo to a completely different location. Then I push my changes there and run composer update in my project to get the changes. But this is a pain.
Do I need to have a sub git in my project in vendor/foo with
git remote add origin https://github.com/thisisme/bar.git. Because "git in git" feels wrong and finally is not really working as git commands seem to interact with the "parent git".

While VonCs answer is correct regarding git, I'm not certainly sure that git submodule support is well aligned with composer(1) vendor dir for packages from a VCS repository. At least I have not experimented much with it and when I use a composer configuration with a VCS git repository, I normally don't need that1.
While composer(1) has support for git for vendor packages, it is on repository level, that is, you can have your own repository for your package (as you have configured it shown in your question) and then composer takes care of updating (or giving a warnings about local changes).
composer(1) supports this with its own remote for the packages (non-bare) clone (in the source install, read on).
So yes, what you describe ("But this is a pain."), is as long as you don't use it to your benefit. While you develop your (cloned) package, you don't need to run composer update all the time.
.git
composer.json
vendor/foo/bar/.git
A Composer project with two Git repositories
This is why IMHO "git in git" must not feel wrong. Similar to git sub-modules, git supports this very well. By default it even keeps track in the parent project of the current revision (changes) of the sub-project but without having the information of the remote - as it is local (gitlink).
You won't see this thought as within the tree, the gitlink would be at vendor/foo/bar and commonly (& given that) vendor is git ignored, no version tracking in the main project for vendor/foo/bar/.git - but there in the sub-project.
This is not a problem as Composer manages that git sub-project for you (the initial clone and further checkouts) in terms of your main project.
And git realizes it is a different project.
You should be able to cd into the package directory within the vendor folder (vendor/foo/bar) and configure your remote(s) there. You can then work within that project and git(1) will work there and not within the parent repository.
To have this work with composer(1) it is important that you configure composer to prefer the source install variant for that repository. This is the preferred-install option and you can configure it for your repository specifically.
{
"config": {
"preferred-install": {
"foo/bar": "source"
}
}
}
From the wording in your question, I assume that you have not yet configured it.
And this is somewhat important as only with the source install, there will be a (non-bare) git clone in vendor/foo/bar and therefore the git checkout with the overall git configuration within the packages folder in the vendor directory (as you have Github configured as the repository source and composer optimizes to take the dist version by default IIRC).
After you changed your configuration to the source install and updated it, cd into vendor/foo/bar and then run git remote -v. It now should show you the "composer" remote(s) for that package.
As you use the develop branch, you can add changes locally but mind the gap that you would also need to push them to the remote repository (Github) before you use composer again to update (at least) that foo/bar package - as while you use git for the development of the foo/bar package now, in your main project you use composer to manage the dependency.
This is the price you have on the payroll using Github instead of a configuration that is more near to the place of work, but at least locally, you can handle the package with "git in git".
This is normally straight forward. One overall price remains thought, due to managing two instead of one repository but that you can't prevent with this kind of composer project [composer only versioned vendor folder]).
Note: If development takes longer than a few hours, it may also make sense to include the new Git sub-project in the backup routine of your parenting project, so that when you remove the folder vendor/foo/bar you have a backup of the (local) Git repository and working tree in it. However, this depends on the project configuration and is your own responsibility.
A bit of a workflow with some hints is also outlined in the composer documentation in Loading a package from a VCS repository.
1 There is a type of setup for a composer project where vendor itself is under git version control, with that git sub-modules can work (very well), but this is most likely not the kind of setup you have for your project, so I skip it for this answer.

If you're working with sail or docker-compose and linking the foo/bar project in the vendor dir is only a temporary until 'it works' solution you could just add it as a volume link. This is what I usually do.
Eg: I'm working on my-project in ~/projects/my-project, I clone the foo/bar repo to ~/projects/bar
Then in the docker-compose.yml I can add the volume:
volumes:
- .:/var/www/html
- ../bar:/var/www/html/vendor/foo/bar
Again, this has a huge assumption on docker being used, but I like to think that everybody is using it these days.

Do I need to have a sub git in my project in vendor/foo with git remote add origin https://github.com/thisisme/bar.git.
That could be achieved with a submodule which allows for your parent Git repository to only store a reference to another repository.
You would use git submodule add for that.
A git clone --recurse-submodule would therefore clone your project with the submodule Git repository in it cloned as well, and checked out to the exact reference you previously committed.

Related

How can I use a gitian environment for building a local project?

I'm working on a project (a fork of bitcoin) that has initially been commited to github that uses the gitian build system. At this point I'd like to set up a local environment that allows me to change code and test changes without commiting them to a git repository.
Is there a way to configure gitian to work with local files that don't have a corresponding git repository, taking advantage of the deterministic build environment without the integrity checks?
If anyone else happens to be dealing with the same tools, the answer is very simple. You can specify a local git repository with filesystem path instead of a remote git URL in your .yml gitian descriptor file.
remotes:
- "url": "/home/user/project"
"dir": "project"
Then branch off your project and commit your changes with git.
When running gbuild, specify the branch/commit with --commit project=branchname.

Vendoring Golang Shared Repository

Trying to move to the officially supported Golang vendoring solution from legacy Godeps workflow.
Scenario:
Repo A===
\
========> Repo C (shared library code)
/
Repo B===
What is the best workflow I can choose for a mid-size (roughly 5-10 member) team of engineers to vendor Repo C for both Repo A and Repo B? Engineers of varying abilities, most of which probably shouldn't need to know the details of this at all?
I'm currently using govendor for this. I'd prefer not to switch but would if there is a tool that provides a better workflow.
This needs to integrate with a CI server running the builds. I can think of 3 scenarios:
Vendor Repo C into A & B:
Pros:
Reproducible Builds
Easy integration with CI
Cons:
Manual and Error Prone - Can easily vendor incorrect code
Engineers need decent knowledge of vendor tool and methodology
Symlink Repo C trunk branch into vendor folders of A & B:
Pros:
Engineers need no knowledge of vendor tool
Low Developer Maintenance
Cons:
Builds not (easily) reproducible
Possibility of including code in build that shouldn't be released
Less Flexible (Repo A and Repo B can't have differing versions of C)
Include Repo C as a git submodule or subtree in Repo A and Repo B (either utilizing vendor or not):
Pros:
Engineers need no knowledge of vendor tool
Easy Setup
Less Maintenance
Reproducible Builds
Cons:
Having to use git submodule or subtree
Finding surprisingly little about this question on the internet. Is there some idiomatic way of doing this? I'm sure there are other ways of doing this; what am I missing?
i suggest to use a manifest based approach with version constraint.
Project A == Manifest
|- Repo A#~1.0.1
|- Repo B#~1.0.1
Repo A == Manifest
|- Repo C#~1.0.1
Repo B == Manifest
|- Repo C#~1.0.5
Repo C == Manifest empty
Which will resolve into
Project A == Resolved Manifest
|- Repo A#1.0.1
|- Repo B#1.0.1
|- Repo C#1.0.5
where ~1.0.1 means >=1.0.1 <1.1.0.
As you see B and A dependency to C are independent, yet within project they are resolved correctly.
In the event A and B would define incompatible dependency to C, an error should occur as the project should not be build-able.
You may prefer to use caret ^ rather than tilde ~, ^1.0.1 -> >=1.0.1 < 2.0.0.
Note that you are not forced to use those 'helpers' such tilde and caret, you may define explicit version range.
You shall decide which constraint to apply given the level of confidence you give to the remote author to correctly upgrade its version number.
Finally,you can use glide to solve that for you.
Starting with Repo C, assuming you already tagged the repos, run glide init, git commit -am 'glide init', git push
Repo A, glide init, glide get git#repo.com/repoc, git commit -am 'glide init', git push
Repo B, glide init, glide get git#repo.com/repoc, git commit -am 'glide init', git push
Finally, Project A, glide init, glide get git#repo.com/repoa, glide get git#repo.com/repob, git commit -am 'glide init', git push
To re install the project, glide install, go build.
Nothing prevent you to tarball ProjectA with its vendor folder, in order to skip the glide install command when you execute the remote installation.
But you normally don t want to commit the vendor folder for a development environment. You d usually add vendor/ to your .gitignore file and run glide install or glide update.
Expect some difficulties in the begin, passed that step, things will work.
Once you jumped to that workflow, note that you ll have to bump every changes on your repos.
That is bloatware when you work both project A and repo B to reach a viable change, so in that case, rather than vendoring repoB into project A (you can leave the manifest definition, but get ride of the repoB folder into vendor/), install repoB as a go module with the go get command.
Doing so the changes are taken in effect immediately on re-build. Once the change set is completed, browse into each repos and bump them appropriately.
Finally you may want to use a version bumper to help you to get it done quick and fast, it happens i did one for my personal usage.
hope this helps.

Heroku and Leiningen: where did my files go?

I have a Leiningen project that is dependent on another Leiningen project. Both are on Github. I cloned the project I am dependent on to the checkouts folder as a Git submodule, which works great in my development environment. I can use the classes from the dependency without even having to add it as a dependency in projects.clj (despite the fact that the documentation says "If you have a project in checkouts without putting it in :dependencies then its source will be visible but its dependencies will not be found").
The main problem is that when I push the project to Heroku, the submodules are cloned automatically but there is no checkouts directory under /app. I guess that Heroku ignores checkouts for some reason.
Presumably I am doing this wrong and there's a right way for me to work in parallel with two Git repos, one of which is dependent on the other. The main issue for me is that I need to be able to deploy my app easily to Heroku. What is the standard way to deal with this situation?
Update: I also noticed that my circle.yml file, which is in the repo, is not in the /app directory. I'm totally confused about what exactly is in the /app directory and where the other stuff disappeared to.
The problem is that heroku runs lein with-profile production compile :all which ignores checkout dependencies (see https://github.com/technomancy/leiningen/issues/1263).
A possible solution is to add :checkout-deps-shares [:source-paths] to your production profile. It's discouraged (according to heroku engineers you really should use an uberjar in production) but it should do the trick.

Externals when migrating from SVN to GIT

Ok, I've read it all, and tried to find solutions to my problem to no avail, so was wondering if anyone would be able to give me the ultimate solution to the migration issue I'm having.
It's to do with using SVN externals in GIT, so hold on to your chairs.
I have looked at the following topics only to find that no one has the exact same setup as I have.
git submodule svn external
git: How do you add an external directory to the repository?
What happens when I clone a repository with symlinks on Windows?
Git Symlinks in Windows
Now my setup is really not that complicated, but I can't work out a way to get it working the way I need it. I have:
Project1
Core
Libs
I then have in my main project
MainProject
MainFolder
file.cs
file1.cs
file2.cs
Core (external of Project1)
Libs (external of Project1)
Obviously this is fine on SVN, as you can use externals, but with sub-modules, you can only create them pointing to the root of the repository, which in this case doesn't quite work for me, since I have both Core and Libs on the same repository. Moving them out isn't an option at this point, since we're still in the migration process, and I need to keep constantly syncing them.
I then thought I could just go and use symlinks (notice I'm on a windows environment), as this way I would be able to checkout my Project1 repository at the same level as my MainProject, and via symlinks make sure my project still thinks everything is where it should.
This magically worked, however, upon doing git status I now noticed Project1 was marked as Untracked files, and by committing this and pushing, and checking out again, my symlink was gone, and I now had a hard copy of my Project1 repository copied into MainProject.
This obviously turned out to be a bit of a nightmare ow, so I was just wondering if anyone could help me with this, and maybe point me towards the right direction.
Thanks in advance,
Marcos
While I believe Michael Geddes is working on supporting symlinks in a future msysgit2, there is one way to get that support right now (that you have mentioned)
"Git Symlinks in Windows"
It allows to restore symlinks on checkout in Windows.
If you add Project1 as a submodule of your main project:
it won't be displayed as untracked files in your git status.
you can add a symlink in MainFolder to (Project1/)Core in order to get the structure you want.

Composer option to use alternative to composer.json?

I've just started using the Composer feature where you tell it to look at local directories for dependencies, so that you can develop a library and something that uses that library in parallel without having to push to git to update all the time, which is awesome. e.g.
"repositories": [
{
"type": "vcs",
"url": "/documents/projects/github/guzzle"
}
],
"require":{
"guzzle/guzzle": "3.7.*#dev"
}
So when you do a composer update, Composer will pull in the version of Guzzle from the local directory, so you can test the code for a library in another application that uses that library without having to push to a repository between each code change.
However I just almost checked in the composer.json for my project with that set - which is obviously not going to work on anyone elses machine.
Is there anyway to tell composer to use a different file than composer.json, or other way to be able to tell composer to use local directories safely, without the high probability of accidentally committing a broken version of composer.json to your repository?
Use the COMPOSER environment variable:
env COMPOSER=composer-dev.json composer install
It has actually been available since at least 2012.
Instead of fetching from a local repository elsewhere you could add the option --prefer-source to the composer install/update command and remove the local repository reference.
That way composer will call git clone the software into the vendor directory, and you can develop both your software and commit to the vendor software, because that also is a fully working git repo.
Adding local repository references is not really recommended. It works when using them for real local software, but maintaining it has it's overhead: You have to mention this repository in every composer.json file that will ever load that software, even if it is only an indirect dependency (i.e. you add a software that needs THIS software as a dependency in your local repo).
Hardcoding the URL of the repository will also prevent you from changing it at will. Even though you could move the repo and change the URL accordingly, all older versions of your software still have the old URL in both composer.json and composer.lock files, and will try to load from there.
It looks like there isn't a way to do this nicely within Composer, however it is possible to hack around it.
In your composer.json file put a comment where you want to hack in some data.
{
"name": "base-reality/intahwebz",
"//": "LOCALHACK",
"require":{
"base-reality/php-to-javascript": ">=0.1.17",
"guzzle/danackguzzle": "3.3.*#dev",
...
...
}
...
}
Then have a separate file composer.local (not committed to Git) that contains the references to local directories:
"LOCALHACK",
"repositories": [
{
"type": "vcs",
"url": "/documents/projects/github/intahwebz-core"
}
],
Add a tiny PHP script called composerLocal.php to generate the new composer.json file
<?php
$srcFile = file_get_contents("composer.json");
$hackFile = file_get_contents("composer.local");
$finalString = str_replace('"LOCALHACK",', $hackFile, $srcFile);
file_put_contents("composer.json", $finalString);
?>
And a little bash script called localupdate.sh to backup the real composer.json file, generate the hacked composer.json, run Composer and then restore the original composer.json file
cp -f composer.json composer.json.bak
php composerLocal.php
composer update
cp -f composer.json.bak composer.json
Running the localupdate.sh script allows you to test the commits locally without having the danger of modifying the actual composer.json file used by the project, so there is less chance of accidentally pushing an invalid composer.json into the repository.
Just to note, Composer doesn't read the files from the respository directory, it reads the commited files in Git so you do need to commit changes made to the library code. The above process just skips the pushing step.
This should also work:
composer config --file=composer2.json && composer install
see https://getcomposer.org/doc/03-cli.md#usage
Easy, just use artifact.
In repositories add this:
{
"type": "artifact",
"url": "path/to/artifact/files/"
},
Now you just need to create the directory and zip a copy of your repository into that dir.
Name zipped files like so:
[vendorname]-[packagename]-[version].zip
example:
querypath-QueryPath-3.0.0.zip
Now you can modify the package locally and it will pull from the zip file instead of the online repo.
In require add it like so and specify version as defined in zip:
"querypath/QueryPath": "3.0.0",
With this method you will have the ability to edit the vendor files and composer will still update any autoloaders relative to the changes and it will leave your changes alone.

Resources