Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8750265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:50:10+00:00 2026-06-13T12:50:10+00:00

I am trying to enforce a policy where each push gets rejected when even

  • 0

I am trying to enforce a policy where each push gets rejected when even one of the commit messages does not satisfy a rule. I’ve distributed a hook to the devs in order for them to use it in their local repos but I also want to enforce this when they push to the origin.

I have two questions:

  1. Should I use the update hook or the pre-receive hook? (I’ve tried to setup an update.secondary hook but it seems to me it doesn’t get fired, while a pre-receive does).

  2. How can I get the message for each commit contained in the push? More specifically, I want each commit message to have a specific “valid” (for my needs) prefix. So I would like to scan for every commit in this push the commit message and validate it before I accept the push.

I am using simple bash to code the hooks.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:50:11+00:00Added an answer on June 13, 2026 at 12:50 pm

    Instead of using chained update hook, I would recommend using VREFS, available with Gitolite V3.
    You can see all its arguments here.

    Since a VREF is basically like a git update hook, you can, like in this script, get the log message for each commits with git log --format=%s -1 $commit:

    Example of a script enforcing a policy on git commit messages:

    #!/bin/bash
    
    refname="$1"
    oldrev="$2"
    newrev="$3"
    result=0
    
    # Make sure we handle the situation when the branch does not exist yet
    if ! [ "$oldrev" = "0000000000000000000000000000000000000000" ] ; then
        excludes=( ^$oldrev )
    else
        excludes=( $(git for-each-ref --format '^%(refname:short)' refs/heads/) )
    fi
    
    # Get the list of incomming commits
    commits=`git rev-list $newrev "${excludes[@]}"`
    
    # For every commit in the list
    for commit in $commits
    do
      # check the log message for ticket number
      message=`git log --format=%s -1 $commit`
      ticket=`echo "$message" | grep -o "^[A-Z]\{2,3\}-[0-9]\+"`
      if [ "$ticket" = "" ] ; then
        echo "Commit $commit does not start with a ticket number"
        result=1
      fi
    done
    
    exit $result
    

    cwhsu mentions in the comments:

    • if you’re trying to write a server side hook with shell script, You probably want to take a look at “Can git pre-receive hooks evaluate the incoming commit?“.
      I finally get the oldrev, newrev and refname by using read in shell script.

    • And here is also what all-zeros SHA1 means.

    • this line “excludes=( ^$oldrev )“, the ‘^‘ simply means exclude!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out how to enforce a 5 minute per post/action rule.
Trying to build out an exception if move.UserId does not equal currentUserId then Redirect
I'm trying to enforce an inheritor of an abstract class to initialize one of
I am trying to enforce a CHECK Constraint in a ORACLE Database on multiple
I'm trying to write a regular expression (via Autohotkey's RegExReplace function) that will enforce
We would like to enforce a new policy for our projects that the master
I am trying to enforce the first name of my model to be any
I'm trying to enforce windows authentication for users of a .Net application on Web
I am trying to implement an XML Schema which will enforce the following the
In Java, I am trying to get DecimalFormat to enforce the sign on an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.