I'd like to run a script automatically when I pull from a repo and the repo has new commits.
I'm thinking of using git hooks but there seems to be no proper hooks for my requirements.
So any other ideas?
As mentioned in "Is there any git hook for pull?", you could try a post-merge
hook.
See for instance:
They are both based on git diff-tree
:
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
}
That function would allow to check if a particular file has changed, and execute a command if it has.
For example:
# `npm install` and `npm prune` if the `package.json` file gets changed
# to update all the nodejs ( grunt ) dependencies deleting the unused packages (not listed into the `package.json` file)
check_run package.json "npm install && npm prune"