-
Notifications
You must be signed in to change notification settings - Fork 440
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
existing git hooks get destroed on install & update #416
Comments
Hi @wommel, That is indeed the way it is currently implemented. Feel free to provide a backup mechanism. |
Hi, what kind of solution do we want here, running multiple git hooks or back up the old one, and insert grumphp git hooks? I am currently working on this, the solution I have now is:
Which one do you prefer @veewee |
I think its a bit overkill to keep backups since the hooks are replaced every time grumphp updates.
It would be very cool if the existing hook could be automatically added to the grumphp shell tasks. (We probably only want to add pre-commit hooks) |
Best way as I see it would be:
One way to accomplish this is to introduce a hook-manager concept. #!/bin/bash
# Runs all executable hookname-* hooks and exits after,
# if any of them was not successful.
#
# Based on
# http://osdir.com/ml/git/2009-01/msg00308.html
data=$(cat)
exitcodes=()
hookname=$(basename $0)
# Run each hook, passing through STDIN and storing the exit code.
# We don't want to bail at the first failure, as the user might
# then bypass the hooks without knowing about additional issues.
for hook in $GIT_DIR/hooks/$hookname-*; do
echo "$hook"
test -x "$hook" || continue
echo "$data" | "$hook"
exitcodes+=($?)
done
# If any exit code isn't 0, bail.
for i in "${exitcodes[@]}"; do
[ "$i" == 0 ] || exit $i
done This file is fairly long, but it isn't going to change between versions. That, unless Git changes a lot in a new version, but that's going to break all hooks all the same, and not like that's going to happen. With this "githook manager" in place, GrumPHP's will rename original hooks into |
@sanmai : did you know that grumphp has a built-in shell task which does exactly what you've pasted here? You only need to configure which shell scripts to run. The way I see it, there is no need for such feature since you allready have a lot of options to choose from:
I think the backup logic is a bit of overkill which just causes maintenance overhead. |
Yeah, right. This is irresponsible and and reckless. I do make backups, but what if someone does not? And you just want to ruin all their hooks with one This discussion just caused me to chmod a-w .git/hooks/* And I'm looking if I can block my composer from ever installing grumphp anywhere. |
Since git hooks arent stored in git, you should always have a backup somewhere. If you don't, you will be screwed at some point. I am open for discussion on the topic, but lets keep it strictly objective. |
The problem is that GrumPHP is supposed to be used by all folks who can't be "following the best practices you've determined as a team" from the start. If they can't code right guess if the do backups. No, they don't. |
The idea of this package is to create one easy to configure git hook for everybody contributing to the project. From that point of view it doesn't make sense to have a custom git hook locally. Can you explain to me why you still want to use your own git hook? What is in there that can't be added to grumphp instead? |
I see no problem in using shell task or what GrumPHP can use to run a script. The problem is that GrumPHP won't make backups of user-installed hooks. Imagine someone who didn't know this package existed, and they had own hooks to do this and that. That, for example, which won't let one to commit on the master. Or that doing some project-specific testing. Or doing post-CI deploys. Hooks can have many uses. And then you do |
My configuration
Steps to reproduce:
Result:
the existing pre-commit hook gets bluntly replaced with the grumphp one.
i would expect grumphp to tell me about this conflict. and also not to replace the existing hook but to put the new one to $HOOKS_DIR/pre-commit.grumphp (or at least backup the old one to HOOKS_DIR/pre-commit.old).
same problem exists for other hooks grumphp uses. (i don't know if it is config dependent which hooks get set but with my config it is commit-msg as well)
The text was updated successfully, but these errors were encountered: