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.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.