How to require commit messages in VisualSVN server

2019-01-16 03:49发布

We've got VisualSVN Server set up as our Subversion server on Windows, and we use Ankhsvn + TortoiseSVN as clients on our workstations.

How can you configure the server to require commit messages to be non-empty?

11条回答
beautiful°
2楼-- · 2019-01-16 04:12

I believe you'll have to setup a pre-commit hook that will check for the message.

Indeed just by googling the first result I got was a perl pre-commit script to do exactly what you intended.

Perl pre-commit hook example (untested)

查看更多
The star\"
3楼-- · 2019-01-16 04:13

Use this pre-commit hook on Windows. It's written in Windows Batch and uses grep command-line utility to check the commit length.

svnlook log -t "%2" "%1" | c:\tools\grep -c "[a-zA-z0-9]" > nul
if %ERRORLEVEL% NEQ 1 exit 0

echo Please enter a check-in comment 1>&2
exit 1

Remember that you'll need a copy of grep, I recommend the gnu tools version.

查看更多
ら.Afraid
4楼-- · 2019-01-16 04:14

Note: This Only Applies To TortoiseSVN

Simply right-click the top level of your Repository. In the context-menu select TortoiseSVN, then Properties, to see this dialog:

enter image description here

Click the New button near the bottom right, and select Log Sizes. Enter the number of characters you want to require for Commit and Lock (10 in example below).

enter image description here

Do a Commit from the top Level directory you just modified. Now your repository requires all users to Comment before Committing changes.

查看更多
爷、活的狠高调
5楼-- · 2019-01-16 04:15

Here is a two part sample Batch + PowerShell pre-commit hook that denies commit a log message with less than 25 characters.

Put both pre-commit.bat and pre-commit.ps1 into your repository hooks folder, e.g. C:\Repositories\repository\hooks\

pre-commit.ps1

# Store hook arguments into variables with mnemonic names
$repos    = $args[0]
$txn      = $args[1]

# Build path to svnlook.exe
$svnlook = "$env:VISUALSVN_SERVER\bin\svnlook.exe"

# Get the commit log message
$log = (&"$svnlook" log -t $txn $repos)

# Check the log message contains non-empty string
$datalines = ($log | where {$_.trim() -ne ""})
if ($datalines.length -lt 25)
{
  # Log message is empty. Show the error.
  [Console]::Error.WriteLine("Commit with empty log message is prohibited.")
  exit 3
}

exit 0

pre-commit.bat

@echo off
set PWSH=%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe
%PWSH% -command $input ^| %1\hooks\pre-commit.ps1 %1 %2
if errorlevel 1 exit %errorlevel%

Note 1 : pre-commit.bat is the only one that can be called by VisualSVN and then pre-commit.ps1 is the one that is called by pre-commit.bat.

Note 2 : pre-commit.bat may also be named pre-commit.cmd.

Note 3 : If you experiment encoding issues with some accented characters and the [Console]::Error.WriteLine output, then add for instance chcp 1252 into pre-commit.bat, next line after @echo off.

查看更多
兄弟一词,经得起流年.
6楼-- · 2019-01-16 04:22

The technical answers to your question have already been given. I'd like to add the social answer, which is: "By establishing commit message standards with your team and getting them to agree (or accept) reasons why one would need expressive commit messages"

I've seen so many commit messages that said "patch", "typo", "fix" or similar that I've lost count.

Really - make it clear to everybody why you'd need them.

Examples for reasons are:

  • Generated Changenotes (well - this'd actually make a nice automatic tool to enforce good messages if I know that they will be (with my name) publically visible - if only for the team)
  • License issues: You might need to know the origin of code later, e.g. should you want to change the license to your code (Some organizations even have standards for commit message formatting - well, you could automate the checking for this, but you'd not necessarily get good commit messages with this)
  • Interoperability with other tools, e.g. bugtrackers/issue management systems that interface with your version control and extract information from the commit messages.

Hope that helps, additionally to the technical answers about precommit hooks.

查看更多
该账号已被封号
7楼-- · 2019-01-16 04:25

I'm glad you asked this question. This is our pre-commit hook script written in common Windows Batch. It denies commit if the log message is less than 6 characters. Just put the pre-commit.bat to your hooks directory.

pre-commit.bat

setlocal enabledelayedexpansion

set REPOS=%1
set TXN=%2

set SVNLOOK="%VISUALSVN_SERVER%\bin\svnlook.exe"

SET M=

REM Concatenate all the lines in the commit message
FOR /F "usebackq delims==" %%g IN (`%SVNLOOK% log -t %TXN% %REPOS%`) DO SET M=!M!%%g

REM Make sure M is defined
SET M=0%M%

REM Here the 6 is the length we require
IF NOT "%M:~6,1%"=="" goto NORMAL_EXIT

:ERROR_TOO_SHORT
echo "Commit note must be at least 6 letters" >&2
goto ERROR_EXIT

:ERROR_EXIT
exit /b 1

REM All checks passed, so allow the commit.
:NORMAL_EXIT
exit 0
查看更多
登录 后发表回答