Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using pre-receive hooks in GIT (using bash on Linux) to filter the push that are allowed into my repo.

I need to filter the push that developers do into my GIT repo, allowing just pushed with this requisites (# is number):

  • # Commits > 0 && # Tags != 0: NO
  • # Commits > 0 && # Tags == 0: YES
  • # Commits == 0 && # Tags > 1: NO
  • # Commits == 0 && # Tags == 1 && Key is correct: YES

Consider branches and other operations same as commits. You can only push a single tag using the right key (specified in tag comment). You can't push a tag with other elements.

The problem is that $refname only have the HEAD ref, so if you do this order:

  1. Commit
  2. Tag (to any revision, even oldies)
  3. Commit

The $refname will point to the last reference (i.e. /refs/heads/master), so doing:

if [[ "$refname" == "refs/tags/"* ]]; then ... fi

Won't work in the order mentionated. I tried to iterate through references using rev-list and for-each-ref, without success.

How could I process the push being received, knowing the number of tags (and getting the comment of each one) to satisfy the upper conditions?

PS: Consider also the situation of pushing with --all option, receiving more than one branch.

share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.