3

在 Collabnet SVN 的预提交脚本中使用以下代码来限制要提交的特定文件扩展名,但它正在提交所有文件。你能告诉我哪里出错了。

#!/bin/sh

REPOS="$1"
TXN="$2"

SVNLOOK=/home/csvn/csvn/bin/svnlook

LOGMSG=`$SVNLOOK log -t "$TXN" "$REPOS" | grep "[a-zA-Z0-9]" | wc -c`

if [ "$LOGMSG" -lt 10 ];
then
  echo -e "\n===========================================================" 1>&2
  echo -e "|| COMMENTS ARE MADE MANDATORY.PLEASE ENTER RELEVANT COMMENT & COMMIT AGAIN Sanjeev sas||" 1>&2
  echo -e "===========================================================" 1>&2
  exit 1
fi

$SVNLOOK changed -t $TXN $REPOS | awk '
BEGIN {
FILTER=".(sh|xls|xlsx|pdf|jpg|JPG|gif|GIF|png|PNG|doc|DOC|docx|DOCX|mpg|swf|avi|mp3|mp4|zip|rar|gz|csv|o|obj|tar|gz|JPEG|jpeg|WMV|wmv|DAT|dat|3GP|3gp|MPEG|mpeg|VOD|vod|ear|jar|war|exe|ppt|PPT|PPTX|pptx|7z|iso|ISO|EAR|WAR|JAR|msg|MSG|rtf|RTF|xlsm|XLSM|vsd|VSD|dot|DOT|camrec|ECF|ecf|mff|MFF|class|CLASS)$"
}
{
 for (i = 1; i < 2; i++) $i = ""; sub(/^ */, "");
 if(match(tolower($1),FILTER))
 { 
     print "File" $1 "is not allowed file type to commit" 
     exit 1
 }
}'    

exit 0
4

3 回答 3

3

下面的脚本对我有用!!让我知道你的想法

#!/bin/bash

REPOS=$1
TXN=$2
AWK=/bin/awk
SVNLOOK="/usr/bin/svnlook";

#Put all the restricted formats in variable FILTER
FILTER=".(sh|xls|xlsx|exe|xlsm|XLSM|vsd|VSD|bak|BAK|class|CLASS)$"

# Figure out what directories have changed using svnlook.
FILES=`${SVNLOOK} changed ${REPOS} -t ${TXN} | ${AWK} '{ print $2 }'` > /dev/null

for FILE in $FILES; do

#Get the base Filename to extract its extension
NAME=`basename "$FILE"`

#Get the extension of the current file
EXTENSION=`echo "$NAME" | cut -d'.' -f2-`

#Checks if it contains the restricted format
if [[ "$FILTER" == *"$EXTENSION"* ]]; then
    echo "Your commit has been blocked because you are trying to commit a restricted file." 1>&2
    echo "Please contact SVN Admin. -- Thank you" 1>&2
    exit 1

fi

done
exit 0
于 2013-02-18T08:59:05.920 回答
0

我和@San有同样的问题,但是@Jijo的回答对我的情况没有直接帮助,因为我在运行SVN服务器时脚本对我不起作用AIX,我已经增强了脚本,如下所示可能适合我的情况。无论如何感谢@Jijo 分享脚本。

#Put all the restricted formats in variable FILTER
FILTER=".(xls|xlsx|exe|pptx|PPTX|vsd|VSD|bak|BAK|class|CLASS|zip|ZIP|doc|DOC|docx|DOCX)$"

# Figure out what directories have changed using svnlook.
FILES=$(${SVNLOOK} changed -t ${TXN} ${REPOS} | ${AWK} '{ print $NF }') > /dev/null

for FILE in $FILES 
do
  EXTENSION=`echo "$FILE" | cut -d'.' -f2-`

  if [[ "$FILTER" == *"$EXTENSION"* ]]; then
    echo "Your commit has been blocked because you are trying to commit a restricted file." 1>&2
    echo "Please contact SVN Admin. -- Thank you" 1>&2
    exit 1
  fi
done
于 2014-03-13T06:54:04.527 回答
0

Windows pre-commit.bat 的解决方案

@ECHO OFF

set REPOS=%1
set TXN=%2
set SVNLOOK="path\to\svnlook.exe"

set FORMATS=*.ext1, *.ext2, *.ext3
:CHECK1
%SVNLOOK% changed -t %TXN% %REPOS% | findstr /R /I ".ext1$" 
if %ERRORLEVEL% EQU 1 goto CHECK2
echo Your commit has been blocked because you are trying to commit a restricted file. Restricted formats %FORMATS% >&2
exit /b 1

:CHECK2
%SVNLOOK% changed -t %TXN% %REPOS% | findstr /R /I ".ext2$" 
if %ERRORLEVEL% EQU 1 goto CHECK3
echo Your commit has been blocked because you are trying to commit a restricted file. Restricted formats %FORMATS% >&2
exit /b 1

:CHECK3
%SVNLOOK% changed -t %TXN% %REPOS% | findstr /R /I ".ext3$" 
if %ERRORLEVEL% EQU 1 goto OK
echo Your commit has been blocked because you are trying to commit a restricted file. Restricted formats %FORMATS% >&2
exit /b 1

:OK
exit /b 0
于 2017-11-14T06:34:46.857 回答