#!/usr/bin/env bash | |
# MIT © Sindre Sorhus - sindresorhus.com | |
# git hook to run a command after `git pull` if a specified file was changed | |
# Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`. | |
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)" | |
check_run() { | |
echo "$changed_files" | grep --quiet "$1" && eval "$2" | |
} | |
# Example usage | |
# In this example it's used to run `npm install` if package.json changed | |
check_run package.json "npm install" |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
How can we share a git hook with the team ? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Failed to run in windows, fix it by add a |
This comment has been minimized.
This comment has been minimized.
This hook doesn't work if you run pull with --rebase option. Do you know how to fix it? Thx! |
This comment has been minimized.
This comment has been minimized.
I forked this to work with changes to .scss and .sass file changes. https://gist.github.com/danielcgold/6de270807fc01c793c9a |
This comment has been minimized.
This comment has been minimized.
It seems like |
This comment has been minimized.
This comment has been minimized.
@robertcasanova take a look at |
This comment has been minimized.
This comment has been minimized.
@MoOx (and anyone interested): If you're using |
This comment has been minimized.
This comment has been minimized.
@sindresorhus this is awesome! thank you! |
This comment has been minimized.
This comment has been minimized.
Does post-merge run when there are conflicts during pull? |
This comment has been minimized.
This comment has been minimized.
No, it won't run. "This hook cannot affect the outcome of git merge and is not executed, if the merge failed due to conflicts." |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
I would add these checks too:
|
This comment has been minimized.
This comment has been minimized.
+1 , same problem. Have you found out the solution?
I've tried to write a post-rebase hook but it didn't work ... |
This comment has been minimized.
This comment has been minimized.
First line missing a |
This comment has been minimized.
This comment has been minimized.
post-rewrite works for me. As side effect it is also executed on amend. http://stackoverflow.com/questions/21307744/git-post-rebase-hook |
This comment has been minimized.
This comment has been minimized.
Awesome! Thanks! It works like a charm. |
This comment has been minimized.
This comment has been minimized.
For package managers that use a lock file, eg. Composer, it would make sense to check if the lock file changed rather than the requirements file, right? In other words:
|
This comment has been minimized.
This comment has been minimized.
Thank you so much, it works like a charm although, I did a few changes on my fork. |
This comment has been minimized.
This comment has been minimized.
On my machine it is running npm install whether package.json is changed or not. The way I am reproducing is by creating a new branch at the current commit and then checking it out. Therefore the files should be identical between the two branches. Anyone have any ideas? cross-posted with stackoverflow: http://stackoverflow.com/questions/43876375/optional-githook-behaving-as-non-optional |
This comment has been minimized.
This comment has been minimized.
For cases where you are pushing to a bare repo and want to use this on a
one should use
Thank you for an extremely useful snippet! |
This comment has been minimized.
This comment has been minimized.
This only deals with changed files right. Suppose I want to check any new files are generated when taking pull, how this solution works? |
This comment has been minimized.
This comment has been minimized.
thanks for the wonderful solution |
This comment has been minimized.
This comment has been minimized.
@sindresorhus Thanks for the wonderful solution. |
This comment has been minimized.
This comment has been minimized.
You have to implement a |
This comment has been minimized.
This comment has been minimized.
How do you run |
This comment has been minimized.
This comment has been minimized.
You should be able to run it as Probably, I also need to add '-e' parameter to the 'grep' function |
This comment has been minimized.
This comment has been minimized.
Thanks! |
This comment has been minimized.
This comment has been minimized.
there is this too https://github.com/jonathantneal/post-npm-install |
This comment has been minimized.
This comment has been minimized.
is there any way to show message like this, before & after hooks execution for if there is any update going to happen if there is no changes to dependency |
This comment has been minimized.
It works like a charm but I had to fork it https://gist.github.com/GianlucaGuarini/8001627