Comments (43)
I ran into this same issue and wasn't 100% happy with the solution above as it is not portable across shells (both PowerShell and Bash, in my case). I solved it by adding a script that skips the following scripts in a non-dev install:
src/Utility/ComposerScripts.php
<?php
namespace Utility;
use Composer\Script\Event;
class ComposerScripts
{
/**
* Run scripts that follow only if dev packages are installed.
*/
public static function devModeOnly(Event $event)
{
if (!$event->isDevMode()) {
$event->stopPropagation();
print("Skipping {$event->getName()} as this is a non-dev installation.\n");
}
}
}
composer.json
(excerpt)
{
"autoload": {
"psr-4": {
"Utility\\": "src/Utility"
}
},
"scripts": {
"post-install-cmd": [
"Utility\\ComposerScripts::devModeOnly",
"cghooks add --ignore-lock"
],
"post-update-cmd": [
"Utility\\ComposerScripts::devModeOnly",
"cghooks update"
]
}
}
from composer-git-hooks.
from composer-git-hooks.
It's working now. Thank you!
from composer-git-hooks.
@devnix you can use
composer update nothing
this command will not update your packages untill you have changes in yourcomposer.json
Yeah, but I guess the whole point is to integrate git hooks into your Composer workflow, and not to modify it 😄
from composer-git-hooks.
Oh damn, sorry, didn't saw the last line. Maybe you could try MYSYS or an equivalent Windows command? I think this would be out of the scope of this repo
from composer-git-hooks.
Here's my solution, though it's linux only:
"scripts": {
"cghooks": "app/Vendor/bin/cghooks",
"post-install-cmd": "test -f app/Vendor/bin/cghooks && app/Vendor/bin/cghooks add --ignore-lock || true",
"post-update-cmd": "test -f app/Vendor/bin/cghooks && app/Vendor/bin/cghooks update || true"
}
from composer-git-hooks.
Problem might be that remove
creates a lock file if running in that order. See #119.
Seems you are safer having it more like @HeWhoWas has it, and maybe even prevent the lock file from being created at all:
"scripts": {
"post-install-cmd": "command -v vendor/bin/cghooks >/dev/null 2>&1 || exit 0; vendor/bin/cghooks add --no-lock",
"post-update-cmd": "command -v vendor/bin/cghooks >/dev/null 2>&1 || exit 0; vendor/bin/cghooks update",
}
from composer-git-hooks.
@devnix the idea for the cghooks.lock
is that it represents the local state of your git hooks. Imagine that the file is committed and a new developer start working on the project. Their hooks will not be installed correctly. The fix for .gitignore
can be done by appending a blank line as well.
The --no-dev
feature was reverted, so, yes it does not work. The previous implementation did not work as expected. I have just updated the release note from 2.7.0
to make that clear. Also, you shouldn't need to specify .git
, that's kind of strange. Could you create a reproducible repo so I can take a look? When you have time of course.
Thanks for the feedback!
from composer-git-hooks.
Hi @BrainMaestro!
I get the point of the lockfile, maybe I did not explain it correctly:
Let's imagine that I configure the "post-install-cmd": "cghooks add --ignore-lock"
line, and I run composer install
. cghooks
will modify my .gitignore
by adding a new line with the lockfile.
Now, my coworker does a composer install
too. As he still does not have any lockfile, cghooks
will modify my .gitignore
again. This will occur each time someone configures a new workspace of the project.
That's why I'm suggesting to rethink the behavior or, at least, the recommendations on the readme file.
The example I provided on the first post solves this problem, and the --no-dev
problem too.
I'm not worried about the .git
problem because it's a strange environment, but if you are curious, it happened on a container based on this:
FROM php:7.0.27-apache
RUN apt-get update && apt-get install git -y
I found that the git rev-parse --git-common-dir
command gives an empty output inside that container (with my volume setted up)
from composer-git-hooks.
Oh right, now I understand. We should actually check the lockfile first before doing the modification. Would you be interested in doing a fix? It shouldn't be too tricky unless we do more sophisticated matching. The alternative which is not to have --ignore-lock
would likely cause accidental commits and mess up the git hook generation for new users. I think I still want to keep the recommendation
For the docker issue, it's because the version of git installed in the container is quite old (2.1.4
- released in 2014) and does not understand the --git-common-dir
output. This can be fixed.
from composer-git-hooks.
Actually, I just checked, and this lockfile behavior (checking if it already exists in the .gitignore
) is already present and should work correctly after #98. I made a commit to fix the --git-dir
problem. Maybe you can install dev-master
and see if it solves the issue for you? As for the last one (needing command -v
), I'm not sure of how to handle it
from composer-git-hooks.
Yes, cghooks
checks if exists a lockfile, and then adds the lockfile to the gitignore. The problem is that if another person checks out the project, cghooks
will not detect any lockfile, and will add a repeated line to the gitignore. This will happen every time you execute composer install
with the --ignore-lock
configuration.
The solution would be to manually modify the gitignore, or parsing the gitignore to avoid duplicating the line.
from composer-git-hooks.
By the way, adba29a seems to work like a charm!
from composer-git-hooks.
Oh, okay, just found your strpos check, you were meaning that, right?
from composer-git-hooks.
Yes, looks like it's broken though
from composer-git-hooks.
Can you try f90b682? should work now
from composer-git-hooks.
vendor/bin/cghooks add --ignore-lock
still reports You did not specify a git directory to use
, using dev-master f90b682
from composer-git-hooks.
But I thought you said it worked before?
from composer-git-hooks.
By the way, adba29a seems to work like a charm!
It seems like I accidentally ran my old composer script with the --git-dir
🤦♂️
from composer-git-hooks.
Can you run git rev-parse --git-common-dir
and git rev-parse --git-dir
and let me know what they return?
from composer-git-hooks.
www-data@b7b360a4808d:~/html$ git rev-parse --git-common-dir
--git-common-dir
www-data@b7b360a4808d:~/html$ git rev-parse --git-dir
.git
from composer-git-hooks.
Okay as expected. I found the bug in the function, so it should work now. 🤞
from composer-git-hooks.
Okay great, can you test the --ignore-lock
behavior? If all is good, I'll make another patch release
from composer-git-hooks.
I tested it too, and I think it's working fine!
from composer-git-hooks.
Okay, great. if you have any ideas for avoiding the command -v
pattern, let me know. I'll close this issue now and create a release. Thanks for the help
from composer-git-hooks.
@devnix, you can use the new release https://github.com/BrainMaestro/composer-git-hooks/tree/v2.8.2 now
from composer-git-hooks.
The only idea I have is to uninstall and reinstall the hooks every install. Also, I would expect to update the hooks with a simple composer install
.
Bundling the update of hooks with composer update
is forcing you to upgrade your composer packages, which is an operation completely unrelated to my point of view.
The neatest workflow I can imagine is to do only install and uninstall operations even without a lockfile, but I fully understand that this idea may conflict with the established philosophy of the project, and would break backwards compatibility.
from composer-git-hooks.
@devnix you can use composer update nothing
this command will not update your packages untill you have changes in your composer.json
from composer-git-hooks.
@devnix I understand the idea behind the lockfile and maybe I can actually get rid of it. I'll consider that for v3. However, I was specifically asking about the issue with needing command -v
from composer-git-hooks.
@BrainMaestro Not sure, I'm still not 100% aware of the internals of a Composer plugin, but I guess that if the hooks are managed by the package automatically with the behavior I've proposed, it should work as expected even when switching the --no-dev
flag on and off.
In fact, the composer.json
would be even easier, por example:
{
"require-dev": {
"overtrue/phplint": "^1.1",
"brainmaestro/composer-git-hooks": "^2.8",
},
"extra": {
"hooks": {
"pre-commit": [
"./vendor/bin/phplint"
],
"post-merge": "composer install"
}
}
}
from composer-git-hooks.
The problem is as a dev dependency, cghooks
won't even be installed in prod environments, so any cghooks
command will definitely fail. --no-dev
or not
from composer-git-hooks.
Hm, I guess we could move our conversation to chat or email to avoid flooding the issue!
from composer-git-hooks.
I'm looking forward to get some free time and try a new strategy purely based on a Composer plugin, without a CLI tool or a lockfile to maintain a list of hooks.
from composer-git-hooks.
@dylan-kerr that's not such a bad solution. @devnix a composer plugin sounds like the right strategy. Maybe that can be adapted to this as a possible 3.0
?
from composer-git-hooks.
Great plugin here. I installed it into a project at work because I want our workflow to be more standardized. However, I am experiencing problems after running a deployment to production. This is because production servers install composer dependencies with the --no-dev
flag.
Because I had to do the deployment, my temporary fix was to remove the commands I had setup.
What is the permanent fix that you suggest for those who install this in an environment with the no-dev
flag?
Thank you
from composer-git-hooks.
For me, my definitive solution was to hack my composer.json
:
"scripts": {
"pre-install-cmd": "command -v vendor/bin/cghooks >/dev/null 2>&1 || exit 0; vendor/bin/cghooks remove",
"post-install-cmd": "command -v vendor/bin/cghooks >/dev/null 2>&1 || exit 0; vendor/bin/cghooks add",
"post-update-cmd": "command -v vendor/bin/cghooks >/dev/null 2>&1 || exit 0; vendor/bin/cghooks update",
},
I will leave it like that until a new version is published fixing this behavior, or until I get some spare time to write my own implementation (not in the short term).
from composer-git-hooks.
@simioluwatomi glad you like it. I would do as @devnix suggested or you can create a simple shell script that does the same (checks for whether cghooks
is present and forwards the parameters if it is, and does nothing otherwise).
I haven't had the time to come up with a broader solution
from composer-git-hooks.
@simioluwatomi glad you like it. I would do as @devnix suggested or you can create a simple shell script that does the same (checks for whether
cghooks
is present and forwards the parameters if it is, and does nothing otherwise).I haven't had the time to come up with a broader solution
Thanks for the suggestion. but I'm no expert at bash scripting.
For me, my definitive solution was to hack my
composer.json
:"scripts": { "pre-install-cmd": "command -v vendor/bin/cghooks >/dev/null 2>&1 || exit 0; vendor/bin/cghooks remove", "post-install-cmd": "command -v vendor/bin/cghooks >/dev/null 2>&1 || exit 0; vendor/bin/cghooks add", "post-update-cmd": "command -v vendor/bin/cghooks >/dev/null 2>&1 || exit 0; vendor/bin/cghooks update", },I will leave it like that until a new version is published fixing this behavior, or until I get some spare time to write my own implementation (not in the short term).
Thanks!!! But I keep getting The system cannot find the path specified.
for all the scripts.
Maybe it helps if I mention that I am running on windows and use git bash.
from composer-git-hooks.
Are you using Windows, @simioluwatomi?
from composer-git-hooks.
Are you using Windows, @simioluwatomi?
Yep! I mentioned that earlier too
from composer-git-hooks.
I think I'll just install it as a normal dependency. I'll think of something later.
from composer-git-hooks.
Hey @devnix I have the same problem on the prod env, as we are running the command with --no-dev. Any updates here so far? I found nothing in the docs.
from composer-git-hooks.
Hey @VanTigranyan, not really, no. I think for now this is the best solution:
For me, my definitive solution was to hack my
composer.json
:"scripts": { "pre-install-cmd": "command -v vendor/bin/cghooks >/dev/null 2>&1 || exit 0; vendor/bin/cghooks remove", "post-install-cmd": "command -v vendor/bin/cghooks >/dev/null 2>&1 || exit 0; vendor/bin/cghooks add", "post-update-cmd": "command -v vendor/bin/cghooks >/dev/null 2>&1 || exit 0; vendor/bin/cghooks update", },I will leave it like that until a new version is published fixing this behavior, or until I get some spare time to write my own implementation (not in the short term).
from composer-git-hooks.
Related Issues (20)
- Hook errors does not stop pre-commit hook with an error HOT 5
- Adding unvalidated hooks (ex. Git Flow hooks) HOT 3
- New Release plz HOT 1
- Unexpected line ends in v2.8.4 HOT 2
- Issue with multiline hook and && HOT 10
- windows composer array scripts as cghooks, only first gets executed when testing by invoking cghooks ${hook} HOT 2
- cghooks remove creates a lock file even if none existed HOT 2
- Impossible to remove pre-commit hook? HOT 2
- Support Symfony 6
- New Tag 2.8.6?
- Symfony/Console 6 compatibility issues
- Stop on failure trigger on pre-commit
- `stop-on-failure` has no effect HOT 2
- No support for php 7.4 HOT 1
- 3.0.0 stable tag HOT 6
- Your requirements could not be resolved to an installable set of packages. HOT 4
- Deprecated: trim() with PHP 8.2 HOT 3
- When will version 3 be stable ? i see version 3 is alpha at present. HOT 2
- Giving shared ownership
- Installation Failed to laravel project
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from composer-git-hooks.