1

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?

can.
  • 2,098
  • 8
  • 29
  • 42

1 Answers1

0

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"
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250