0

In our Git repository, after pulling files from origin to local, it is absolutely crucial to run another script which does some synchronizing. However, as programmers (including me) are prone to forgetting even crucial things, I think I'd better of writing a tiny bash script:

git pull origin master
# do our synchronizing stuff

However, that would still not solve the problem: Any developer could still do plain git pull without using the script. So, what I have in mind is: Setting up the Git repository so that in only allows pull with a special parameter. If the special parameter is not present, it would return a custom message. Like so:

git pull origin master -special-parameter
# do our synchronizing stuff

Doing git pull origin master without -special-parameter would end in git pull not allowed directly. Please use our special script. Is this possible?

The only solution coming to my mind is changing user rights, revoking all rights for the repository, only granting special_script_user full rights and wrapping the git pull inside su -c. However, that would not be really elegant.

cis
  • 1,259
  • 15
  • 48

1 Answers1

1

There are git hooks for that. Just define your script as the post-merge hook and it will automatically be executed after a git pull or a git merge (there are variables that help you differentiate between the two).

Be aware though that git hooks are not part of the repository content, meaning you cannot just commit a hook at your end and everybody else magically also has them.

A solution is to commit the hook scripts to the repository and asking each developer to activate them when they first clone the repository. This can be done e.g. by copying or linking them to the .git/hooks directory

ln -s hooks/post-merge .git/hooks/

and has to be done only once.

Nils Werner
  • 34,832
  • 7
  • 76
  • 98