Skip to content

Commit

Permalink
feature/VIH-5605 : added pre commit message hook
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinabennett committed Mar 10, 2020
1 parent 7cae164 commit 96fd07d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ LC_ALL=C

local_branch="$(git rev-parse --abbrev-ref HEAD)"

valid_branch_regex="^(feature\/VIH-[0-9]{3})[a-zA-Z0-9._-]+$"
valid_branch_regex="^(feature\/VIH-[0-9]{4})[a-zA-Z0-9._-]+$"

message="There is something wrong with your branch name. Branch names in this project must start with feature/VIH-XXX. Your commit will be rejected. You should rename your branch to a valid name and try again."
message="There is something wrong with your branch name. Branch names in this project must start with feature/VIH-XXXX-anyNameOfBranch. Your commit will be rejected. You should rename your branch to a valid name and try again."

if [[ ! $local_branch =~ $valid_branch_regex ]]
then
Expand Down
29 changes: 29 additions & 0 deletions .githooks/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh

COMMIT_MSG_FILE=$1
COMMIT_SOURCE=$2
SHA1=$3


# Get the current branch name
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
# exstract a part of branch name with the VIH-XXX
TRIMMED=$(echo $BRANCH_NAME | sed -e 's/.*\/*\(VIH-[0-9]\{4\}\).*/\1/')
# get the current commit message
currentmsg=$(cat "$COMMIT_MSG_FILE")
message="Commit message must start with the prefix 'feature/VIH-XXXX : ' folowing by 8 or more characters. Your commit will be rejected. You should rename your commit to a valid name and try again."
valid_mesg_regex="^(feature\/VIH-[0-9]{4} : )([:_, a-zA-Z0-9.-]{8,})+$"

feature="feature/"

if [[ ! $currentmsg =~ $valid_mesg_regex ]]
then
echo "$message"
exit 1
fi
exit 0
fi




7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@ To turn on\off ZAP security scans individually such as Spider\AjaxSpider\ActiveS

##Branch name git hook will run on pre commit and control the standard for new branch name.

The branch name should start with: feature/VIH-XXX (X - is digit).
The branch name should start with: feature/VIH-XXXX-branchName (X - is digit).
If git version is less than 2.9 the pre-commit file from the .githooks folder need copy to local .git/hooks folder.
To change git hooks directory to directory under source control run (works only for git version 2.9 or greater) :
$ git config core.hooksPath .githooks

##Commit message
The commit message will be validated by prepare-commit-msg hook.
The commit message format should start with : 'feature/VIH-XXXX : ' folowing by 8 or more characters description of commit, otherwise the warning message will be presented.


0 comments on commit 96fd07d

Please sign in to comment.