How to require commit messages in VisualSVN server?

后端 未结 10 1937
故里飘歌
故里飘歌 2020-12-07 12:00

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 se

10条回答
  •  天涯浪人
    2020-12-07 12:09

    Here's a Windows Shell JScript that you can use by specifying the hook as:

    %SystemRoot%\System32\CScript.exe //nologo <..path..to..script> %1 %2
    

    It's pretty easy-to-read, so go ahead an experiment.

    BTW, the reason to do this in JScript is that it does not rely on any other tools (Perl, CygWin, etc.) to be installed.

    if (WScript.Arguments.Length < 2)
    {
        WScript.StdErr.WriteLine("Repository Hook Error: Missing parameters. Should be REPOS_PATH then TXN_NAME, e.g. %1 %2 in pre-commit hook");
        WScript.Quit(-1);
    }
    
    var oShell = new ActiveXObject("WScript.Shell");
    var oFSO = new ActiveXObject("Scripting.FileSystemObject");
    
    var preCommitStdOut = oShell.ExpandEnvironmentStrings("%TEMP%\\PRE-COMMIT." + WScript.Arguments(1) + ".stdout");
    var preCommitStdErr = oShell.ExpandEnvironmentStrings("%TEMP%\\PRE-COMMIT." + WScript.Arguments(1) + ".stderr");
    
    var commandLine = "%COMSPEC% /C \"C:\\Program Files\\VisualSVN Server\\bin\\SVNLook.exe\" log -t ";
    
    commandLine += WScript.Arguments(1);
    commandLine += " ";
    commandLine += WScript.Arguments(0);
    commandLine += "> " + preCommitStdOut + " 2> " + preCommitStdErr;
    
    
    // Run Synchronously, don't show a window
    // WScript.Echo("About to run: " + commandLine);
    var exitCode = oShell.Run(commandLine, 0, true);
    
    var fsOUT = oFSO.GetFile(preCommitStdOut).OpenAsTextStream(1);
    var fsERR = oFSO.GetFile(preCommitStdErr).OpenAsTextStream(1);
    
    var stdout = fsOUT && !fsOUT.AtEndOfStream ? fsOUT.ReadAll() : "";
    var stderr = fsERR && !fsERR.AtEndOfStream ? fsERR.ReadAll() : "";
    
    if (stderr.length > 0)
    {
        WScript.StdErr.WriteLine("Error with SVNLook: " + stderr);
        WScript.Quit(-2);
    }
    
    // To catch naught commiters who write 'blah' as their commit message
    
    if (stdout.length < 5)
    {
        WScript.StdErr.WriteLine("Please provide a commit message that describes why you've made these changes.");
        WScript.Quit(-3);
    }
    
    WScript.Quit(0);
    

提交回复
热议问题