pre-commit - get lock owner

Lintz
Lintz
Hi all, i've got the below script which detects if a file is already locked and if so displays a message to the user. What I want to also display is the user which currently has the file locked but can't work it out.    Below is my current script. Anyone know how to get and display the lock owner of a file?    @echo off    :: Set all parameters  set repository=%1  set repopath=%2  set user=%3    :: Set path to svnlook  set svnlook=C:\Program Files\VisualSVN Server\bin\svnlook.exe    :: First check that the lock exists already.  :: In that case svnlook prints the lock description.  "%svnlook%" lock "%repository%" %repopath% | findstr /B /L "UUID Token:" > NUL 2>&1    :: If the lock does not exist, allow locking  if ERRORLEVEL 1 exit 0    :: Now check the lock's owner  "%svnlook%" lock "%repository%" %repopath% | findstr /C:"Owner: %user%" > NUL 2>&1    :: If the person locking matches the lock's owner, allow locking  if %ERRORLEVEL% EQU 0 exit 0    :: Otherwise, return failure  echo "Error: %repopath% is already locked by ???" >&2  exit 1

Last updated

Lintz
Lintz
I was finally able to get the owner of the locked file. Below is my updated script.      @echo off    set SVN_REPOS=%1  set SVN_PATH=%2  set SVN_USER=%3    set lock_owner = ""  set lock_message = ""    :: Set path to svnlook  set svnlook=C:\Program Files\VisualSVN Server\bin\svnlook.exe    REM Skip one row of output, take second token, and delimiter is " "  for /f "skip=1 tokens=2" %%U in ('"%svnlook%" lock %SVN_REPOS% %SVN_PATH%') do (   set lock_owner=%%U   goto :check_owner  )    :check_owner  if "%lock_owner%" == "" exit 0  if "%lock_owner%" == "%SVN_USER%" exit 0    for /f "skip=5 tokens=*" %%U in ('"%svnlook%" lock %SVN_REPOS% %SVN_PATH%') do (   set lock_message=%%U  )    @echo on  if not "%lock_message%" == "" echo Lock message: %lock_message% 1>&2  ::echo Sorry %SVN_USER%. Error: %SVN_PATH% locked by %lock_owner%. 1>&2  echo %SVN_PATH% is currently locked by %lock_owner%. 1>&2  exit 1  

1-2 of 2

Reply to this discussion

You cannot edit posts or make replies: You should be logged in before you can post.