gitgithubgithookspost-commit

Git Post Commit hooks to find name of branch


I want to create a post commit hook through which I need to send a notification to the committing developer that branch pushed is not following our naming convention. So what I would like to know is:

  1. How to read the pushed branch name
  2. How to check if the branch name follows a certain pattern like "origin/name/issueid"

We want to inform user when their branch isn't follow the naming convention.


Solution

    1. Assuming you decided to go the post-receive route that jthill suggests you should look at this answer to get the branch name: https://stackoverflow.com/a/13057643/1504372. There's other solutions there that might be more appropriate depending on your specific situation. Here's the official doco: http://git-scm.com/docs/githooks. (Start by trying to echo $1 and oldrev to get a feel for what's available to you.)
    2. Your second issue calls for a regex. http://www.itworld.com/article/2693361/unix-tip-using-bash-s-regular-expressions.html