본문 바로가기

IT/개발 프로세스

svn pre-commit hook in windows(using powershell)

커밋 메시지에 대한 고찰 과 더 나은 방법에 대한 제안

특정 개발자만 필터

개발자들 author_a, author_b, author_3 중에 한명이 커밋을 했다면
svnlook author -r 22 D:\slacksvn | findstr "author_a author_b author_3"

pre-commit.bat

@echo off

SET REPOS=%1
SET TXN=%2
 
svnlook author -t %TXN% %REPOS% | findstr "metdoloca  dfdf NX00000127 aaaaa"
if not "%ERRORLEVEL%" == "0" GOTO IT_IS_NOT_OUR_TEAM

GOTO FIND_SUCCESS

:FIND_SUCCESS
POWERSHELL D:\test\checkLogMsg.ps1 %REPOS% %TXN%
if not "%ERRORLEVEL%" == "0" GOTO INVALID_FORMAT
exit 0

:INVALID_FORMAT
echo "FAIL"
echo. 1>&2
  echo "first line regex = '^[\+\-].{1,50}$'" 1>&2
  echo "second line have to be empty. or just one line" 1>&2
  echo find reference http://conf.nexusgames.co.kr/pages/viewpage.action?pageId=16059476 1>&2
exit 1
:IT_IS_NOT_OUR_TEAM
exit 0

powershell

D:\test\checkLogMsg.ps1
param(
    [string]$REPOS,
    [string]$TXN
)

$psFilePath = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent 
$commitMessage = svnlook log -t $TXN $REPOS

if ( $commitMessage.Count -ge 1 )
{
    # 규칙 채크/ 첫글자는 + or - 이고 50글자 이하
    if(-not ($commitMessage[0] -match '^[\+\-].{1,50}$') ) 
    {
        exit 1
    }

    if( $commitMessage.Count -ge 3)
    {
        if( -not [string]::IsNullOrEmpty($commitMessage[1]) -or ([string]::IsNullOrEmpty($commitMessage[2])) )
        {
            exit 2
        }
    }
    exit 0
}
exit 3


검색한 링크 정리

http://kkamagistory.tistory.com/119

http://mwultong.blogspot.com/2006/09/windows-xp-regex-findstr.html

https://gist.github.com/olleolleolle/434197

https://gist.github.com/rasmuskl/1476866

https://stackoverflow.com/questions/564631/svn-pre-commit-hooks

http://mwultong.blogspot.com/2006/07/error-level-errorlevel.html

https://blogs.msdn.microsoft.com/oldnewthing/20080926-00/?p=20743

http://mwultong.blogspot.com/2006/08/compare-strings-in-batch-file.html


http://egloos.zum.com/katalog/v/4637905


https://stackoverflow.com/questions/5330419/unable-to-write-an-error-message-when-on-a-pre-commit-hook


http://blogs.wandisco.com/2011/11/10/an-introduction-to-subversion-hook-scripts-on-windows/


https://stackoverflow.com/questions/32216084/how-to-display-pre-commit-error-message


svn pre-commit error message windows




https://www.google.co.kr/search?q=powershell+argument&oq=powershell+argu&aqs=chrome.1.69i57j0l5.3539j0j4&sourceid=chrome&ie=UTF-8

https://stackoverflow.com/questions/2157554/how-to-handle-command-line-arguments-in-powershell

https://www.google.co.kr/search?q=powershell+write+file&oq=powershell+write+file&aqs=chrome..69i57j0l5.9943j0j7&sourceid=chrome&ie=UTF-8

https://blogs.technet.microsoft.com/gbordier/2009/05/05/powershell-and-writing-files-how-fast-can-you-write-to-a-file/


powershell get script file path

https://stackoverflow.com/questions/1183183/path-of-currently-executing-powershell-script

https://stackoverflow.com/questions/5466329/whats-the-best-way-to-determine-the-location-of-the-current-powershell-script

https://stackoverflow.com/questions/8343767/how-to-get-the-current-directory-of-the-cmdlet-being-executed

https://stackoverflow.com/questions/24987114/getting-resolved-file-path-in-powershell

https://stackoverflow.com/questions/13126175/get-full-path-of-the-files-in-powershell


powershell 정규표현식

https://technet.microsoft.com/ko-kr/library/2007.11.powershell.aspx

powershell line count

powershell line count string

https://stackoverflow.com/questions/29889495/powershell-count-specific-string-in-text-file

https://stackoverflow.com/questions/8936264/how-to-count-number-of-rows-in-powershell

powershell string split

https://blogs.technet.microsoft.com/heyscriptingguy/2014/07/17/using-the-split-method-in-powershell/

powershell find newline

https://social.technet.microsoft.com/Forums/windowsserver/en-US/a7a81568-7275-4c48-bfb0-f23d6b4a6412/split-newline?forum=winserverpowershell

https://stackoverflow.com/questions/325953/how-can-i-replace-newlines-using-powershell

https://blogs.technet.microsoft.com/heyscriptingguy/2014/09/07/powertip-new-lines-with-powershell/

Select-String count

https://stackoverflow.com/questions/29889495/powershell-count-specific-string-in-text-file

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/select-string?view=powershell-5.1

powershell select-string newline

https://stackoverflow.com/questions/13651530/powershell-select-string-remove-carriage-return

https://stackoverflow.com/questions/31700861/powershell-select-string-add-breaks-new-line

https://social.technet.microsoft.com/Forums/windowsserver/en-US/d3a668ee-cde3-4006-bfa7-ff470c238436/selecstring-with-pattern-more-big-than-one-line?forum=winserverpowershell

https://www.vistax64.com/powershell/115004-new-lines-regular-expressions.html

pohwershell line count

https://technet.microsoft.com/en-us/library/ee692800.aspx

https://www.thomasmaurer.ch/2010/07/powershell-count-your-code-lines/

https://stackoverflow.com/questions/11561497/powershell-script-to-count-number-of-lines-ommitting-a-line-containing-a-specifi

pohwershell return code

https://blogs.msdn.microsoft.com/powershell/2006/10/14/windows-powershell-exit-codes/

powershell split line into array


powershell separate string lines

powershell foreach-object new line

https://danielbrannstrom.wordpress.com/2010/10/16/powershell-iterate-lines-in-a-multiline-string/

https://social.technet.microsoft.com/Forums/windows/en-US/78d5a5fa-bb82-4c2d-a2c1-96d518b9bd74/need-to-read-text-file-as-an-array-and-get-elements-from-each-line-of-array-using-powershell?forum=winserverpowershell

powershell foreach-object new line

powershell foreach

https://blogs.technet.microsoft.com/heyscriptingguy/2014/04/28/basics-of-powershell-looping-foreach/

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/foreach-object?view=powershell-5.1

powershell do while

powershell array count

powershell empty string check

powershell if not

http://www.computerperformance.co.uk/powershell/powershell_if_not.htm

powershell regex

https://ss64.com/ps/syntax-regex.html

http://mwultong.blogspot.com/2007/06/regex-wildcard.html