问题
I am aware that this question was already asked answered on SO, but that answer was simply to remove the hook. I need to fix the hook instead of removing it.
We are running VisualSVN Server on Windows 2012 with Win 7 clients. I have been tasked with disabling the stealing of locks (I know this is not best practice use of SVN, but the bosses want it). Here is the .bat file I currently have in place for our pre-lock hook (found on the web):
@ECHO OFF
:: Set all parameters. Even though most are not used, in case you want to add
:: changes that allow, for example, editing of the author or addition of log messages.
set repository=%1
set rev_path=%2
set userName=%3
:: If a lock exists and is owned by a different person, don't allow it
:: to be stolen (e.g., with 'svn lock --force ...').
FOR /F "delims=: tokens=1*" %%a IN ('svnlook lock "%repository%" "%rev_path%"') DO if %%a==Owner (set LOCK_OWNER=%%b)
:: If we get no result from svnlook, there's no lock, allow the lock to
:: happen:
if "%LOCK_OWNER%"=="" (
exit /b 0
)
:: If the person locking matches the lock's owner, allow the lock to
:: happen:
if "%LOCK_OWNER%" = " %username%" (
exit /b 0
)
:: Otherwise, we've got an owner mismatch, so return failure:
echo "Error: %rev_path% already locked by %LOCK_OWNER%." >&2
exit /b 1
I have also tried writing an app using SharpSVN (I've used that to create a post-commit hook before). Both the .bat file and my SharpSVN script return this same error:
Lock token URI '
C:\Program Files\VisualSVN Server>"C:\Program Files\VisualSVN
Server\bin\VisualSVNServerHooks.exe" case-insensitive
-tC:\Repositories\DIT_TEST /go-home.txt Jeremy.Coulson
C:\Program Files\VisualSVN Server>C:\SVNAdmin\SVNPreLockHook.bat
C:\Repositories\DIT_TEST /go-home.txt Jeremy.Coulson
' has bad scheme; expected 'opaquelocktoken'
If you want to break the lock, use the 'Check For Modifications' dialog or the repository browser.
Here are the settings in our Visual SVN server:
I'm thinking that I have to somehow provide this opaquelocktoken
to the hook script, but I'm not sure how.
回答1:
If your problem is still actual, here is my way to avoid it.
The root cause is that SVN will take ANY "echoing" as a lock-token at pre-lock phase.
To avoid this I'm writing pre-lock hooks in vbs files (Visual Basic Script) which are to be run from pre-lock.bat hook file.
The pre-lock.bat file that run script is like this
@echo off
Wscript somescript.vbs %1 %2 %3 %4 %5
@echo on
Please note, that you have to use "Wscript" and not "Cscript"
When there is a need to use script result as exiting condition, then
@echo off
FOR /F "usebackq tokens=*" %%r in (`Cscript %1\hooks\somescript.vbs %1 %2 %3 %4 %5`) DO set res=%%r
@echo on
@exit %res%
The vbs way to pass value back to the .bat file is: Wscript.Echo some_value
来源:https://stackoverflow.com/questions/33548032/svn-lock-hook-error-expected-opaquelocktoken