简体   繁体   中英

SVN Post Commit Hook Batch Windows

I have a Windows Server running Visual SVN Server to store our repositories. Also on that server is our test copy.

I'm trying to set up a simple SVN post-commit hook so it updates that test copy automatically every time I commit something

In Visual SVN in the post-commit hooks I've set up like this

"C:\Program Files (x86)\VisualSVN Server\bin\updatescripts.bat" D:\inetpub\TESTCOPY

Then that batch file has a simple update like this

PATH=%PATH%;"C:\Program Files (x86)\VisualSVN Server\bin\"
svn update %1

If I run the batch file in the server by double clicking on it or from command line works fine. When committing something from my laptop it freezes and doesn't give me any error and locks the test copy so then I need to go in and run a clean up.

Visual SVN service is running as network service and this aacount has full access to the bin folder and the test copy on the server.

Any idea how to set up a simple svn update post commit hook anyone?

Thanks Fede

I had a similar problem and it turned out to be that SVN likes paths to use forward slashes instead of backslashes.

Try this:

set MYPATH=%1

:: Transform backslashes to forward slashes
set MYPATH=%MYPATH:^\=/%

svn update %MYPATH%

You're running the svn update command. Exactly what working copy are you trying to update?

The parameter being passed is the Repository's path . This points not to a working directory, but to the directory that contains the Subversion master repository. This is the same directory where your post commit hook is stored.

Subversion hooks do not have access to the user's working directory, so you can't manipulate the user's files. Hook scripts usually should be using svnlook and not svn . By doing this, you prevent yourself from getting into any sort of trouble.

It is possible to update a Subversion working copy on the server, if you know the location:

PATH=%PATH%;"C:\Program Files (x86)\VisualSVN Server\bin\"
set SVN_WORK_DIR=C:\SVN\workdir"
svn update %SVN_WORK_DIR%

However, I wouldn't recommend this because it ties up Subversion. The user who did the commit would have to wait until the update is complete before Subversion returns the control of the prompt back to the user.

After trying a million different things this worked for me...

I put this in my post-commit hook "C:\\Program Files\\VisualSVN Server\\bin\\svn.exe" update "C:\\my path\\" where my path is the path to the working copy to be updated

Also I had to change the service to run as local system

That is really not the way you want to do that. What you should do is use something like Jenkins to watch your repository. Jenkins can watch your repository, and it when it changes, update your test copy, kick-off builds, run automated tests, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM