2015-11-05 118 views
0

我知道這個問題已經在SO上被要求回答,但答案只是爲了消除鉤子。我需要修復鉤子而不是刪除它。SVN鎖定掛鉤錯誤:預計opaquelocktoken

我們使用Win 7客戶端在Windows 2012上運行VisualSVN Server。我的任務是禁用鎖的竊取(我知道這不是使用SVN的最佳實踐,但老闆需要它)。這裏是.bat文件我目前已經制定我們的預鎖鉤(在網絡上找到):

@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 

我也試着寫的用SharpSVN一個應用程序(我用的是創建一個職位 - 之前提交掛鉤)。無論是.bat文件和我的SharpSVN腳本返回同樣的錯誤:

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. 

下面是我們的視覺SVN服務器設置:

screen shot from VisualSVN

我在想,我必須以某種方式提供這opaquelocktoken到鉤子腳本,但我不知道如何。

回答

0

如果你的問題仍然存在,這是我的方法來避免它。

根本原因是SVN會在預鎖定階段將任何「回顯」作爲鎖定令牌。

爲了避免這種情況,我在vbs文件(Visual Basic Sc​​ript)中編寫預鎖鉤子,這些鉤子將從pre-lock.bat鉤子文件運行。

運行腳本是這樣

@echo off 
Wscript somescript.vbs %1 %2 %3 %4 %5 
@echo on 

請注意,您必須使用「WScript的」,而不是「Cscript命令」

當存在的lock.bat前檔需要使用腳本結果作爲退出條件,那麼

@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% 

VBS的方式來傳遞值回.bat文件是: Wscript.Echo some_value