Common Types of Subversion Hooks

前端 未结 16 2055
無奈伤痛
無奈伤痛 2020-11-28 04:01

What kinds of hook scripts are people using for Subversion? Just general ideas but code would be great too!

相关标签:
16条回答
  • 2020-11-28 04:30

    post-commit hook to send email notification that something changed in the repository to a list of emails. You need sendmail.exe in the same folder than your hook file, along with sendmail.ini.

    You also need a file post-commit.tos.txt next to your post-commit.cmd to list the mail recipients. The file should contain:

    user1@example.com,user2@example.com,user3@example.com
    

    Here is the hook code:

    @ECHO OFF
    setlocal
    
    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :: Get subversion arguments
    set repos=%~1
    set rev=%2
    
    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :: Set some variables
    set tos=%repos%\hooks\%~n0.tos.txt
    set reposname=%~nx1
    set svnlookparam="%repos%" --revision %rev%
    
    if not exist "%tos%" goto :END
    
    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :: Prepare sendmail email file
    set author=
    for /f "tokens=* usebackq" %%g in (`svnlook author %svnlookparam%`) do (
      set author=%%g
    )
    
    for /f "tokens=* usebackq delims=" %%g in ("%tos%") do (
      set EmailNotificationTo=%%g
    )
    set SendMailFile=%~n0_%reposname%_%rev%.sm
    
    echo To: %EmailNotificationTo% >> "%SendMailFile%"
    echo From: %reposname%.svn.technologie@gsmprjct.com >> "%SendMailFile%"
    echo Subject: [%reposname%] Revision %rev% - Subversion Commit Notification  >> "%SendMailFile%"
    
    echo --- log [%author%] --- >> "%SendMailFile%"
    svnlook log %svnlookparam% >> "%SendMailFile%" 2>&1
    echo --- changed --- >> "%SendMailFile%"
    svnlook changed %svnlookparam% --copy-info >> "%SendMailFile%" 2>&1
    
    echo .>> "%SendMailFile%"
    
    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :: Send email
    type "%SendMailFile%" | "%~dp0sendmail.exe" -t
    
    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :: Clean-up
    if exist "%SendMailFile%" del "%SendMailFile%"
    
    
    :END
    endlocal
    
    0 讨论(0)
  • 2020-11-28 04:32

    A hook to notify the bug/issue management system of changes to repository. Ie. the commit message has issue:546 or similar tag in it that is parsed and fed to the bug management system.

    0 讨论(0)
  • 2020-11-28 04:34

    We use a commit hook script to trigger our release robot. Writing new release information to a file named changes.txt in our different products will trigger the creation of a tag and the relevant artifacts.

    0 讨论(0)
  • 2020-11-28 04:34

    Windows pre-commit hook to check that log contains something.

    @ECHO OFF
    setlocal
    
    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :: Get subversion arguments
    set repos=%~1
    set txn=%2
    
    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :: Set some variables
    set svnlookparam="%repos%" -t %txn%
    
    ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :: Make sure that the new svn:log message contains some text.
    set bIsEmpty=true
    for /f "tokens=* usebackq" %%g in (`svnlook log %svnlookparam%`) do (
       set bIsEmpty=false
    )
    if '%bIsEmpty%'=='true' goto ERROR_EMPTY
    
    echo Allowed. >&2
    
    goto :END
    
    
    :ERROR_EMPTY
    echo Empty log messages are not allowed. >&2
    goto ERROR_EXIT
    
    :ERROR_EXIT
    :: You may require to remove the /b below if your hook is called directly by subversion
    exit /b 1
    
    :END
    endlocal
    
    0 讨论(0)
  • 2020-11-28 04:38

    The most common one I think is to allow people to change revision comments after comitting.

    You need to enable the 'pre-revprop-change' hook script to allow that. The example provided, if enabled allows editing only the comment property and only be the original comitter. Great for correcting typos.

    0 讨论(0)
  • 2020-11-28 04:43

    I am using the pre-revprop-change hook that allows me to actually go back and edit comments and such information after the commit has been performed. This is very useful if there is missing/erroneous information in the commit comments.

    Here I post a pre-revprop-change.bat batch file for Windows NT or later. You can certainly enhance it with more modifications. You can also derive a post-revprop-change.cmd from it to back up the old snv:log somewhere or just to append it to the new log.

    The only tricky part was to be able to actually parse the stdin from the batch file. This is done here with the FIND.EXE command.

    The other thing is that I have had reports from other users of issues with the use of the /b with the exit command. You may just need to remove that /b in your specific application if error cases do not behave well.

    @ECHO OFF
    
    set repos=%1
    set rev=%2
    set user=%3
    set propname=%4
    set action=%5
    
    ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :: Only allow changes to svn:log. The author, date and other revision
    :: properties cannot be changed
    ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    if /I not '%propname%'=='svn:log' goto ERROR_PROPNAME
    
    ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :: Only allow modifications to svn:log (no addition/overwrite or deletion)
    ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    if /I not '%action%'=='M' goto ERROR_ACTION
    
    ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :: Make sure that the new svn:log message contains some text.
    ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    set bIsEmpty=true
    for /f "tokens=*" %%g in ('find /V ""') do (
     set bIsEmpty=false
    )
    if '%bIsEmpty%'=='true' goto ERROR_EMPTY
    
    goto :eof
    
    
    
    :ERROR_EMPTY
    echo Empty svn:log properties are not allowed. >&2
    goto ERROR_EXIT
    
    :ERROR_PROPNAME
    echo Only changes to svn:log revision properties are allowed. >&2
    goto ERROR_EXIT
    
    :ERROR_ACTION
    echo Only modifications to svn:log revision properties are allowed. >&2
    goto ERROR_EXIT
    
    :ERROR_EXIT
    exit /b 1 
    
    0 讨论(0)
提交回复
热议问题