【问题标题】:SVN Lock Hook Error: expected opaquelocktokenSVN 锁钩错误:预期 opaquelocktoken
【发布时间】:2016-02-06 11:49:31
【问题描述】:

我知道这个问题已经在SO 上得到回答,但这个答案只是为了移除钩子。我需要修复钩子而不是移除它。

我们在带有 Win 7 客户端的 Windows 2012 上运行 VisualSVN 服务器。我的任务是禁止窃取锁(我知道这不是 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.

以下是我们 Visual SVN 服务器中的设置:

我在想我必须以某种方式将这个opaquelocktoken 提供给钩子脚本,但我不确定如何。

【问题讨论】:

    标签: svn visualsvn-server


    【解决方案1】:

    如果您的问题仍然存在,这是我避免它的方法。

    根本原因是SVN会在预锁阶段将任何“回声”作为锁定令牌。

    为了避免这种情况,我在 vbs 文件(Visual Basic 脚本)中编写了预锁定挂钩,这些挂钩将从 pre-lock.bat 挂钩文件中运行。

    运行脚本的pre-lock.bat文件是这样的

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

    请注意,您必须使用“Wscript”而不是“Cscript”

    当需要使用脚本结果作为退出条件时,则

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

    将值传回 .bat 文件的 vbs 方法是: Wscript.Echo some_value

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-19
      • 2010-11-22
      • 2018-05-29
      • 1970-01-01
      相关资源
      最近更新 更多