-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add support for git repos #5
base: master
Are you sure you want to change the base?
Conversation
Just for completeness, it seems one alternative to this patch is outlined in this blog in the section "Require Any Git Repository with Composer". In your project's main composer.json file you can specify something like the following:
That should work for a git repo that does not have a However, the composer documentation seems to discourage this approach and notes some limitations:
|
src/Handler/GitHandler.php
Outdated
else { | ||
$version = 'master'; | ||
} | ||
return sprintf('git init && git remote add origin %s && git remote update --prune origin && git checkout %s', ProcessExecutor::escape($url), ProcessExecutor::escape($version)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For both L71 and L54 -- I think git remote update
is a newer command? We don't have a good way to control the git
version here. It might be safer to use something like:
git fetch <remote> <refspec>
git fetch --depth 1 <remote> <refspec>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup - makes sense.
@jmcclelland That's a neat idea. The patch looks pretty clean. I think the patch is generally welcome. I'm adding a couple comments / suggestions. One other general suggestion - there should be some kind of coverage in the test-suite. The smallest possible thing would be to update
That's up to you. If I were you, I would decide based on the feelings about transitive dependencies:
So one part sounds similar; another part sounds different.
|
$process = new ProcessExecutor($io); | ||
$cfs = new Filesystem(); | ||
$git = new Git($io, $config, $process, $cfs); | ||
if (file_exists($wd)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tested, but I see these two code-paths (based on file_exists()
), and it makes me imagine the following use-case:
- In top-level
composer.json
, addextra.downloads
definition with agit
URL. - Run
composer install
. - In top-level
composer.json
, editextra.downloads
and change thegit
commit/tag. - Run
composer install
.
I guess the idea is that step 2 makes a new folder, and step 4 updates that same folder.
But what if that folder doesn't have any .git
data? For example:
- In top-level
composer.json
, addextra.downloads
definition with azip
URL. - Run
composer install
. - In top-level
composer.json
, editextra.downloads
definition to agit
URL. - Run
composer install
.
At step 4, shouldn't we clear out the folder before doing any git operations?
(IIRC, this only matters for extra.downloads
in the top-level folder. In other contexts, there's a higher level rm -rf
.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback! And yes, I agree, I think adding git support here is a better way forward than adding the alternative.
I can work on extending the test coverage.
Regarding the file_exists
code paths - I added it without much thought in the interest of speed and efficiency (if we already have the directory in place and it's checked out to the same commit, we move on very quickly). However, it does sacrifice correctness in the use case you provide (and perhaps others we haven't even thought of).
I think, in the context of this extension, the .composer-downloads/<id>-<hash>.json
is kinda like the composer.lock
file. So, on composer install
we could test for the existance of that file. If it doesn't exist and we have a folder, than rm -rf
the folder and install from scratch. If it does exist, we could assume the contents properly describe the folder and run git fetch
(if someone mucked with the folder git will return an error and that seems reasonable).
On composer update
we would need to compare composer.json
with .composer-downloads/<id>-<hash>.json
. If we are moving from zip to git, then rm -rf
the folder and start from scratch. If the repo URL changes, rm -rf
and start from scratch, and otherwise git fetch
.
Having spelled all this out, I'm leaning towards your initial suggestion of just rm -rf
. I'm not sure all the added complexity is worth the small efficiency gain. Open to writing the more complex approach though if you prefer.
We could make it another parametr?
we can't necessarily count on the commit being in the main branch. Alternatively, we could alter our syntax to allow us to specify a branch in the composer.json file?
I'm trying to add support for something like this:
I'm really not sure if this PR makes sense, so feel free to close if I'm way off base.
I'm actively working on converting my old drupal 7 drush-make build system do a drupal 8+ composer system and am struggling with converting a drush make file with about 40 or so CiviCRM extensions (most of them without a composer.json file) specified as git addresses plus git commits.
This composer plugin seems to be doing the same but for zip files.
Does adding git support make sense? Is there a better way to do what I'm trying for?