开发者

POST-COMMIT SCRIPT of SVN to check commit log for PRODUCT-ID using shell script

开发者 https://www.devze.com 2023-02-14 05:25 出处:网络
I am new to Linux as well as for Subversion. I had a task to check the syntax of the commit message to contain PRODUCT ID. If its not present I have pass a message to user saying an invalid format usi

I am new to Linux as well as for Subversion. I had a task to check the syntax of the commit message to contain PRODUCT ID. If its not present I have pass a message to user saying an invalid format using SHELL SCRIPT.

Below are the steps I had followed after a lot search in google, For the PRE-COMMIT hook the code is:

#!/bin/sh  
set -e  
/PATH-TO-REPOSITORY/hooks/CommentSyntax.sh "$1" "$2"  

My CommentSyn开发者_如何学编程tax.sh script is,

#!/bin/sh  
REPOS="$1"  
TXN="$2"  
SVNLOOK=/usr/bin/svnlook  
regex="PRODUCT-[0-9]*"  
if [ `"$SVNLOOK" log -t "$TXN" "$REPOS"` =~ ${regex} ]; then  
    exit 0  
else  
  echo "" 1>&2    
  echo "Please make your commit comment start with PRODUCT-XXX" 1>&2  
  exit 1  
fi

Whenever I am trying to check-in the code, am getting the below error,

srikanth:~/testing$ svn ci -m "PRODUCT-123"
Sending        two.java
Transmitting file data .svn: Commit failed (details follow):
svn: Commit blocked by pre-commit hook (exit code 1) with output:
[: 22: PRODUCT-123: unexpected operator

Please make your commit comment start with PRODUCT-XXX

I am not sure where I gone wrong. Request your valuable advice on the same.


The test command knows no =~ operator. Relpace the

if [ `"$SVNLOOK" log -t "$TXN" "$REPOS"` =~ ${regex} ]; then  

line by

if "$SVNLOOK" log -t "$TXN" "$REPOS" | head -n1 | grep -q '^PRODUCT-[0-9][0-9]*' ; then

head -n1 select the first line of the commit, grep checks the regexp.

0

精彩评论

暂无评论...
验证码 换一张
取 消