-1

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.

David Deutsch
  • 13,210
  • 3
  • 41
  • 45
Anil
  • 33
  • 5

2 Answers2

1
  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

(Meta commentary: People might down vote this post because it doesn't look like you tried to solve it yourself. You'll have better luck if you post about what's not working, preferably with code / output / error messages. You'll also get more precise help this way, a complete answer to your question at this point would basically require writing the whole hook myself. This is of course just my take, feel free to disregard. :-) )

Community
  • 1
  • 1
lostphilosopher
  • 3,723
  • 4
  • 24
  • 37
  • 1
    "A complete answer to your question at this point would basically require writing the whole hook myself." And this is exactly why we downvote such questions, because the lack of context creates a "do it for me" atmosphere that is bad for reviewers and less helpful for future searchers with questions! – Two-Bit Alchemist Jul 20 '15 at 15:51
0

This code will be written in post-commit of git hooks i.e. vim .git/hooks/post-commit

if git branch --show current | grep developer
then
        echo " i am developer"
        git push -u origin developer
else
        echo "i am master"
        git push -u origin master
fi

The above code will push into developer branch if commit is done by developer else push into master branch. In my git , I had two branches : -master (main branch) -developer (feature branch)