atlassian sourcetree - How to prevent git commit if specific phrase in changes is detected? -


i noticed patterns, developers tend - committing javascript tests fdescribe or fit left in them (which means 1 test/suite running), found in review phase, nice catch small things earlier. wondering if there way configure git prevent commit if pattern detected within changes?

that's classical job git commit hooks (man githooks); example, standard script samples in .git/hooks, can add script pre-push folder (make executable!).

this example script git project checks commit names, if replace the

git rev-list 

line like

git diff $remote_sha $local_sha 

and grep suspcious strings, e.g.

git diff $remote_sha $local_sha|grep -e '^\+.*(fdescribe|fit)' 

you can make happen case.

#!/bin/sh  # example hook script verify pushed.  called "git # push" after has checked remote status, before has been # pushed.  if script exits non-zero status nothing pushed. # # hook called following parameters: # # $1 -- name of remote push being done # $2 -- url push being done # # if pushing without using named remote arguments equal. # # information commits being pushed supplied lines # standard input in form: # #   <local ref> <local sha1> <remote ref> <remote sha1> # # sample shows how prevent push of commits log message starts # "wip" (work in progress).  remote="$1" url="$2"  z40=0000000000000000000000000000000000000000  while read local_ref local_sha remote_ref remote_sha     if [ "$local_sha" = $z40 ]             # handle delete         :     else         if [ "$remote_sha" = $z40 ]                     # new branch, examine commits             range="$local_sha"         else             # update existing branch, examine new commits             range="$remote_sha..$local_sha"         fi          # check wip commit         commit=`git rev-list -n 1 --grep '^wip' "$range"`         if [ -n "$commit" ]                     echo >&2 "found wip commit in $local_ref, not pushing"             exit 1         fi     fi done  exit 0 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -