SVN post-commit for Windows

Posted by Dan on Feb 5, 2008 @ 12:03 PM

As I mentioned early I've been working on a SVN post-commit script. We've got a SVN repository that will be modified by several remote developers and I really need to keep an eye on this repository and I need to closely monitor changes to this repository.

There are two major functions that I needed in my post-commit script:

  1. I needed to update the working copy on my server
  2. I needed to e-mail the changes to myself, so I know when developers are making changes

There are an abundant of examples showing off how to do this in various *nix flavors, but I couldn't find any good Windows-based solutions that didn't require Perl to be installed on the server. That led me to create the following post-commit.bat script.

@ECHO OFF
REM *************************************************************
REM * this sets the arguments supplied by Subversion            *
REM *************************************************************
SET REPOS=%1
SET REV=%2

REM *************************************************************
REM * define directory paths                                    *
REM * you *must* add any paths for command line tools you plan  *
REM * since SVN does not include the Windows %PATH% environment *
REM * variable for security reasons.                            *
REM *                                                           *
REM * DIR  - the current hooks directory                        *
REM * PATH - a user set path of where executables are located   *
REM *                                                           *
REM *************************************************************
SET DIR=%REPOS%/hooks
REM *************************************************************
REM * make sure to add the path to the SendEmail executable     *
REM *************************************************************
SET PATH=%PATH%;%DIR%;C:\Utils

REM *************************************************************
REM * define the path to the working copy of your code          *
REM *                                                           *
REM * the default working_copy folder would be:                 *
REM * file:///%REPOS%                                           *
REM *************************************************************
SET WORKING_COPY=c:\path\to\working\copy

REM *************************************************************
REM * define e-mail parameters                                  *
REM *************************************************************
SET SITENAME=My Code Base
SET SMTP_SERVER=smtp.yourdomain.com
SET EMAIL_TO=svnupdates@yourdomain.com
SET EMAIL_FROM=svnupdates@yourdomain.com
SET SUBJECT=SVN Update - %SITENAME% - rev %REV% - %REPOS%

REM *************************************************************
REM * update the local working copy                             *
REM * this will sync the new changes to your servers copy       *
REM *************************************************************
svn update %WORKING_COPY%

REM *************************************************************
REM * generate the header to use for the e-mail message         *
REM *************************************************************
ECHO The following changes were made to the code: > %DIR%/email.txt
ECHO. >> %DIR%/email.txt

REM *************************************************************
REM * dump the log of changes to the e-mail message             *
REM *************************************************************
svn log %WORKING_COPY% -v -r "%REV%" >> %DIR%/email.txt

REM *************************************************************
REM * dump the diff changes to the e-mail message               *
REM *                                                           *
REM * WARNING: Generates tons of output                         *
REM *                                                           *
REM * NOTE: this is optional, you can remove this information   *
REM *       if you do not want a verbose message of changes     *
REM *************************************************************
svn diff %WORKING_COPY% -c "%REV%" --no-diff-deleted >> %DIR%/email.txt

REM *************************************************************
REM * send the e-mail message to the user                       *
REM *                                                           *
REM * NOTE: to create a SendEmail.log file, append:             *
REM *                                                           *
REM *        -l %DIR%/SendEmail.log                             *
REM *                                                           *
REM *       at the end of the line below.                       *
REM *************************************************************
sendEmail -s %SMTP_SERVER% -t %EMAIL_TO% -f %EMAIL_FROM% -u "%SUBJECT%" -o message-file=%DIR%/email.txt

A couple of notes on the script above:

  • You'll need to download SendEmail in order to send the e-mail messages. In the environmental variable %PATH% you'll want to make sure to include the path where you copied the SendEmail.exe. In the example above, the SendEmail.exe is located in the C:\Utils directory.
  • Make sure to go through the script and replace any variables declared with the SET command with the values that coorelated to your environment.
  • In my case I required a working copy to be placed on my server, as it's used as a global development environment. If you do not require a local working copy, you can comment out the svn update %WORKING_COPY% line (by placing the command REM in front of the line.) You would then change your WORKING_COPY variable to the URL of your SVN repository—which would be file:///%REPOS%.
  • The svn diff command can generate a ton of information. In most use cases, you probably do not want to add this information to the e-mail output.

If you have any problems getting this script working, I recommend you check out my blog entry on debugging SVN repository hook scripts in Windows.

Categories: JavaScript, SQL, HTML/ColdFusion, Flex/Flash, Java, Source Code

86 Comments

  • Too good! I am searching post hook batch files ... and this is the right choice. :)
  • This helped me immensely!  Thank you!

    For others that come across this, Here's where I got stumped. If you're running subversion with apache, this script will be run as Apache. I needed to run this against a network path like: \\server\share I couldn't, because apache didn't have network access rights.

    I had to update the apache service (and perhaps the subversion service) to run using my user account. It worked fine after that.
  • I find passing off to python or ruby allows you to do much more powerful things.

    @echo off
    set REPOS=%1
    set REV=%2

    c:\SVN\ServiceRoot\bin\svnlook changed -r %REV% %REPOS% >
    c:\SVN\Repo\CodeBoy\hooks\changed.txt
    c:\python25\python C:\SVN\Repo\CodeBoy\hooks\updateChanged.py

    This way you can only call an update on the modified paths instead of killing your box trying to update the entire checkout.
  • Great script, thanks!
    I have users set up with their smtp addresses as their user names. Is there a way to
    SET EMAIL_TO= with the value of the user committing the file(s)?
  • @Seth:

    The follow SVN command would get you the author of an update:

    svnlook author -r "%REV%" "%REPOS%"

    See this URL for more usage:
    http://svnbook.red-bean.com/en/1.4/svn.ref.svnlook...

    You'd need to capture that output and get it into a variable to send it to the author (since the post-commit unfortunately doesn't pass author information to script.)

    Just curious as to why you'd only want to notify the commiter via e-mail--since they'll know immediately if their commit passed or failed.
  • I want to use this script to notify the IT team that code has been committed.
    The from address in the message ought to be the author of the commit.
    The to address is the person that will push the files.
  • @Seth:

    Gotcha. Here's a link that should help you capture the author information from the svnlook command:

    http://weblogs.asp.net/lorenh/archive/2006/03/24/4...

    Pay attention to the comment that mentions:

    FOR /F "tokens=*" %%i in ('%~dp0sometool.exe') do SET TOOLOUTPUT=%%i
  • @Dan
    Thanks for your response.
    Since sometool.exe is svnlook, how would that be set?

    When I have this:

    FOR /F "tokens=*" %%i in ('%~dp0C:\svnserve\bin\svnlook author -r "%REV%" "%REPOS%"') do SET TOOLOUTPUT=%%i

    and

    SET EMAIL_FROM=%TOOLOUTPUT%

    this is the post-commit log:

    The filename, directory name, or volume label syntax is incorrect.
    Dec 03 09:34:34 myusername sendEmail[4084]: WARNING => The argument after -f was not an email address!
    Dec 03 09:34:34 myusername sendEmail[4084]: ERROR => You must specify a 'from' field! Try --help.
  • @Dan,
    I got this to work by copying the svnlook.exe into the hooks folder and using the syntax

    FOR /F "tokens=*" %%i in ('%~dp0svnlook.exe author -r "%REV%" "%REPOS%"') do SET TOOLOUTPUT=%%i

    Since svnlook.exe is 53 kb, this will do for now until I understand the %~ function.

    -Peace
  • @Seth:

    You don't need svnlook in the hooks folder, you just need to specify the path to executable. As my other blog entry on troubleshooting post-commit hooks talks about, hooks do not have access to environmental variables.

    This means your batch file has a PATH environment that's empty (which is why svnlook might run from a command prompt without the full path.)

    Anyway, just use a path to the svnlook.exe and all should be well.
  • @Dan,
    There is a path set:
    SET PATH=%PATH%;%DIR%;C:\svnserve;C:\svnserve\utils
    I would think [svnlook] would be available like [svn log] and [sendEmail].

    Since this is a standalone Subversion instance running as a Windows service, and the root repository folder is located on a different drive, and the FOR command in conjunction with the %~ command is not fully understood by me, perhaps this is why I choose to get it to work by placing svnlook in the hooks folder.
  • @Dan,
    I think I have it running now without having to have svnlook in the hooks directory.
    I removed the %~dp0, and just have the line as

    FOR /F "tokens=*" %%i in ('C:\svnserve\svnlook.exe author -r "%REV%" "%REPOS%"') do SET TOOLOUTPUT=%%i

    and then I can place

    SET EMAIL_FROM=%TOOLOUTPUT% for use in the sendEmail command.
  • When I run this script on a commit using tortoise the commit hangs forever. Is there anyway that I can see what the script is doing or does anyone have any idea what would cause it to hang?
    Thanks!
  • @Evan:

    See my blog entry on debugging post-commit scripts for tips:

    http://blog.pengoworks.com/index.cfm/2008/2/5/Debu...
  • @Dan Thanks! The output helped me to find the issue which I fixed but now I am having an authentication realm issue.

    I get the following in my log file:

    C:\apache>svn update c:\checkout\procedures
    Authentication realm: <http://address:80>; Subversion repository
    Password for 'SYSTEM':

    I never created an account named system and I am committing from another machine using tortoise. Where does the script get its login info?

    Thanks!
  • @Evan:

    SYSTEM is a special Windows account. Sounds like the SYSTEM account does not have access to write tot he c:\checkout\procedures folder.
  • Daniel Fredericks's Gravatar
    Daniel Fredericks
    Hey dan,
    When I run the script, I get this error in my log file....the email runs, though without any info in it, but I get this error...can you explain this...all we need to do is run the script so we can update our development area.

    Certificate information:
    - Hostname:
    - Valid:
    - Issuer:
    - Fingerprint:
    (R)eject, accept (t)emporarily or accept (p)ermanently? svn: OPTIONS of 'https://server name/TestingRepository/trunk': Server certificate verification failed: issuer is not trusted (https://server name:8443)
    Feb 06 14:56:56 server sendEmail[6196]: Email was sent successfully! From: <email address> To: <another email address> Subject: [SVN Update - subversion testing - rev 18 - E:\Repositories\TestingRepository] Server: [mailserver:25]
  • It looks like it doesn't like your SSL cert. My guess is your using a home grown SSL cert and SVN is unable to access the URL because of the invalid cert. Either fix the cert or try to see if there's a way to get SVN to use the cert by adding it to a cert store (I'm not even sure that's possible with the SVN client utils.)
  • @Daniel:

    Also, use the physical path to the repository files instead of the URL--which will completely get rid of the need to use SSL altogether.
  • Good Morning Dan G. Switzer,

    Are you referring to the UNC that is used through-out SVN? I don't believe we are using URL's for Repositories and or working files areas. We do have certs developed by Verasign for our system, so I am perplexed as to why it would not like them. Perhaps we are looking at the wrong kind of cert? I work with Daniel Fredericks and we really like SVN, provided we can get past this issue.
  • My bag, I was thinking about another issue we had, Daniel explained to me that we in fact are using a secure link with SVN. Sorry for the confusion.
  • Cool stuff! I got my Windows post commit hook working by simply following the above mentioned steps.
  • Daniel Fredericks's Gravatar
    Daniel Fredericks
    Dan,
    Just wanted to thank you for this code. We figured out what our issue was and this code works great.
  • @Evan and @Dan:

    I received the same output:
    Password for 'SYSTEM':

    And I solved it by adding the --username ARG and --password ARG options to the end of the svn up command.
  • Hi Dan,

    The srcript works well when I run it from a command promt, but when it is executed by svn after a commit it "freezes".
    The commit actually happens but tortoise freezes, as a result the working copy is locked and I need to do a cleanup and update to get it back to normal.
    Any idea what I am doing wrong?
  • @Regis:

    See the entry for some ways to debug:
    http://blog.pengoworks.com/index.cfm/2008/2/5/Debu...

    It could be a permissions issue as well. Also, if your repository is really large, it can take a while to update the working copy, which can give the appearance that the commit has been frozen.
  • Thanks Dan, I've used the trick you suggest to get some logs and it's indeed a permission issue:
    Authentication realm: <http://www.xxx.co.uk:80>; Subversion repository
    Password for 'SYSTEM':

    I'm doing the check-in via tortoise over http as you can see.
    Is there is a setting I must add in the apache configs?
  • @Regis:

    It shouldn't have anything to do with Tortoise (unless that's what you're using in the post-commit to do the update.) Instead it has to do with the permissions within the context that the post-commit is running.

    You can probably solve the problem by adding authentication information via the command line to your svn commands.
  • Thanks, I found this helpful.
  • Dear Dan,

    Thank you so much for sharing this as it really saved my hours to look into the issue - now, I can see the logs and can at least try to look into the problem.

    Anyway, I did almost the same but it is not still working for me. I mean, my SVN copy is not being auto updated to the web server on same computer.

    It is showing below message in my logs:
    'svn' is not recognized as an internal or external command,
    operable program or batch file.

    I know that it will be really too much as if I ask you to guide me but there is no other way around for me - I have already searched a lot about it and finally back to you :)

    Please let me know with some quick ways so that I can try it at my end.

    Thank you very much!
  • @Vishwash:

    See tip #1 in this post:

    http://blog.pengoworks.com/index.cfm/2008/2/5/Debu...

    Commit hooks run with an empty environment, so unless you specify the full path to the SVN executable (or updated the SET PATH line to reflect the path to your SVN install) the hook won't be able to located the executable.
  • Dear Dan,

    Thank you so much for your prompt response and nice support. It was something I also was expecting but didn't try well last time. Now it worked - really thank you so much for this blog, I would love to share it with more people.

    Anyway, now I am able to run the "svn update" but as per the logs, I am still getting an error for "Error validating server certificate for 'https://www.website.com:443':" - I hope, I'll be able to solve this by looking at some place within :)

    Anyway, once again, thank you so much!
  • Hi Dan - thanks again as everything worked for me perfectly now. I was getting the certificate error because I copied the code from other svn and just placed it.

    Anyway, the message was still giving for certificate issue on my local server too so I removed the certificate from local and now it is updating the code so that's the only good thing for me :)

    At some other time, I will find a way to make it to work with proper ssl certificate too :) and will share if useful.

    Thank you!
  • Hi Dan.
    I have a problem with permission.
    As the post-commit batch file run on the server, I need to know the user name and password of the user that commited the latest changes.
    How do I solve these permission issues?

    Thanks,
    Janiv.
  • @Janiv:

    First, if you access the repository via the file system you shouldn't need to use a username/password for updating.

    If you do end up having to use a username/password, to the best of my knowledge, you'll need to hardcode the user account info into your hook. If you go this route, I'd recommend setting up a specific account for doing this.
  • Thank you for your quick response.
    How do I access the repository via the file system?

    for the line:
    svn log file:///%REPOS% -v -r "%REV%" >> %DIR%/email2.txt

    I get
    svn: Unable to open an ra_local session to URL
    svn: Unable to open repository 'file:///D:%5CRepositories%5CWeRSystem'
    svn: Can't open file '\D:\Repositories\WeRSystem\format': The filename, directory name, or volume label syntax is incorrect.


    Thanks again,
    Janiv.
  • @Janiv:

    You'd want to do something like:

    svn log file:///C:/path/to/svn/repository -v -r "%REV%" >> %DIR%/email2.txt

    You'll use the full path to the repository folder on the server.
  • Thanks Dan,

    That's exactly what I did: (svn log file:///%REPOS% -v -r "%REV%" >> %DIR%/email2.txt).
    I get the following error:

    svn: Unable to open an ra_local session to URL
    svn: Unable to open repository 'file:///D:%5CRepositories%5CWeRSystem'
    svn: Can't open file '\D:\Repositories\WeRSystem\format': The filename, directory name, or volume label syntax is incorrect.

    Thanks again,
    J.
  • @Janiv:

    No, you did: file:///%REPOS%

    I suggested: file:///C:/path/to/svn/repository

    Manually supply the path, do not rely on %REPOS%. Reduce everything to values you completely control.

    Also, make sure you have a version of SVN compatible with your actual repository. It's possible the version of SVN you're using is an older copy than the one actually being used by the live repository.
  • Thank you,
    But this is exactly the same value (shouldn't it be so?).
    I can see in my debug messages that the %REPOS% return the appropriate value.

    Do you have any other suggestions for my error messages?

    Thank you SO MUCH again.
    J.
  • I used this to get the author's name

    set EMAIL_FROM=%USERNAME%

    Since the username is different from the from part of the email address, I did this (we have a small number of developers, so this was easy)

    set EMAIL_FROM=%EMAIL_FROM:user1=user1email@domain.com%
    set EMAIL_FROM=%EMAIL_FROM:user2=user2email@domain.com%

    ....
    etc
  • I faced one problem. We use the file:/// method and our repository is on a network share. This worked fine when the user had a drive letter mapped to the network share but not if the user had his repository url as \\network\share

    so: file:///Z:\repository\path worked
    but I can't make file:///\\network\share\repository\path to work.
  • Well done! Thanks to @Dan and @Seth.
  • I'm use post-commit hooks. Settup hook and svn server on windows 2003.
    But when commit code => error : Post-commit hook failed (exit code 1) with output:
    Permission is denied
    Help me fix this bug. Thanks
  • @Alvin:

    Looks like the error message is pretty specific. Sounds like you're trying to execute code the hook doesn't have permissions to execute. You need to check your permissions.
  • Thank you so much for the e-mail notification example! I was wasting a lot of time with complex python scripts when it is so simple the way you've put it together.
  • Hi,

    We changed the server installation and something has stopped working.
    We have the following code, in post-commit script

    echo FOR /F "tokens=*" %%i in ('%SVNLOOK% author -r "%REV%" "%REPOS%" ') do SET UNAME=%%i >> %DIR%/hook.log

    This is not working and the UNAME is empty.

    However, if I run the following code:

    echo %SVNLOOK% author -r "%REV%" "%REPOS%"  >> %DIR%/hook.log

    I do get the right user name.

    Why is that?

    Thanks,
    Janiv.
  • of course without the echo ....
  • @Janiv:

    I'm not sure. However, make sure you're logging the output of the execution of the hook--it's usually the only way to debug hard to find issues.

    See this article for debugging tips--like logging the output:
    http://blog.pengoworks.com/index.cfm/2008/2/5/Debu...
  • Hey,

    Thank you.
    This is WINDOWS version issue (do you believe it??).
    We moved to Windows Enterprise edition and
    FOR /F "tokens=*" %%i in ('%SVNLOOK% author -r "%REV%" "%REPOS%" ') do SET UNAME=%%i >> %DIR%/hook.log

    doesn't work anymore.
    Now we have to put the %SVNLOOK% author -r "%REV%" "%REPOS%" row in double quotes.

    This is the way it works with our current windows version (enterprise)

    FOR /F "tokens=*" %%i in ('"%SVNLOOK% author -r "%REV%" "%REPOS%""') do SET UNAME=%%i >> %DIR%/hook.log

    Thanks,
    Janiv.
  • Hi,

    I stumbled upon this blog, which helped me to get my post-commit script to run for the most part. What we are trying to achieve is - whenever a commit happens on the trunk, we want to synchronize all available branches in the repository with the trunk automatically and then send out an email with the log details.
    I am using svn merge command in a FOR LOOP, but when I try to write its output to a file (within the loop eg: >>email.txt), I keep getting this error message in my log file "The process cannot access the file because it is being used by another process."

    Has anyone come across this issue before, and if yes, do you have any suggestions how to close and open the file for each iteration?

    Regards,
    Kavita
  • @Kavita:

    I've never seen the problem, but I suspect files are being kept open during the merge. I also suspect you're going to run into problems trying to do this with trunk merges needing manual resolves with branches--which is going to cause issues with trying to automate this process.

    Personally, I wouldn't even try to automate a merge process.
  • Hi
    Thanks a lot for this excellent hook. I have been looking for such a long time doing this on a Windows 2003 server... sendEmail program is really useful, and all your tips regarding debugging hook and security issues are great.

    There's still one thing I can't achieve.. it's updating a remote working copy...
    When I want to update a local working copy on my subversion server, no problem it's working fine. But as soon I want to update a working copy on different server via network drive or network path, that's not working.
    I know that system account does not have access to network drive, as it's an empty environment..
    Any clue for this problem ?
    Thanks in advance
    and once again great job
  • @Jies:

    Take a look at something like "runas" which allows you to execute programs/batch files with specific privileges:

    http://technet.microsoft.com/en-us/library/cc77267...

    Other than that, I don't have any recommendations.
  • Thanks for the quick answer. I have tried runas command as you advice. I thought it was a good solution, but I am still stuck with my problem.
    Even if I am using /savedcreds option, with your debugging solution I can see it keeps asking me a password when in an emtpy environment.
    Here is what I had at the end :

    c:\windows\system32\runas /savedcreds /user:localaccount "C:\Program Files\Subversion\bin\svn.exe update \\remoteserver\sharedfolder --username svnuser --password svnpass"

    When I launch this command, it's working fine. But with svn post-commit, there is no way.. For each command, it asks a password.
    :-(

    Before your post, I have worked on ssh solution, and I almost find a solution.
    I have installed on my remote server OpenSSH, and with a ssh client, I can run a command directly on the remote server by using this :

    ssh2 user@remoteserver svn update c:\workingcopy_on_remoteserver

    Obviously I need to enter a password. But with SSH you can use public shared key to avoid using a password. I am still trying to make it working, but I am confindent..

    Any help welcome !
  • @Jies:

    What if you put the put the SVN stuff in a batch file and then use the runas to run the batch file with runas.

    You might also take a look at PsExec:
    http://technet.microsoft.com/en-us/sysinternals/bb...

    Maybe it can help.
  • I have found a workaround solution for the problem with the certificate in the post-commit file. Here's a way to fix the problem on Windows

    1. On the server perform an SVN command of some type that will show the dialog about the server. Choose Accept Permanently. For TortoiseSVN you can start an SVN Checkout and choose to browse the repository, this should force the message up, if needed. If you do not get the dialog then you should already have the file you need for the certificate.
    2. Next, find out what username is used when the post-commit script runs. Using the logging techniques described on this blog, add a 'set' command, then do an SVN commit to generate the log. Look for USERNAME= to get the user that the post-commit script is being executed as.
    3. Find the user folder in C:
    Documents and Settings. First find the folder for the user you are logged in as, for example, if you are logged in as svnuser find the C:\Documents and Settings\svnuser folder. In that user folder find Application Data\Subversion\auth\ssl.server folder, you should see one or more files with numbers for the names. Open up the files and look for a string at the bottom that references the server you want to access. Once you find the file copy it.
    4. Now find the folder for the username used during the post-commit script and look for the Application Data\Subversion\auth\ssl.server folder there. Drop in the file you copied from your login user. This should fix the problem with SVN not being able to find the certificate during the post-commit.

    I needed to be able to do this for svnsync since I will be contacting a server outside of our internal network, hope this helps someone else out.
  • @Dan:
    Thanks again for your advice. I have tried now almost every solution I could find but I am still stuck at the same point.. As soon as my command is executed by the system (post-commit), it doesn't work. Either it keeps asking me a password, or an answer yes or no, or it tells me there is an access denied or error...

    Here is my differents issues :

    -Runas
    Even with /savedcreds option, I have to enter at least one time my password... so I have tried sanur (http://www.commandline.co.uk/sanur_unsupported/ind...) to transmit the password to runas command.. When I check post-commit log, I don't see anymore the password question, but unfortunately it doesn't work better...

    PsExec:
    Good utility once again on command line, but within post-commit environment, it gives nothing, worse the process is blocked and I have to kill it in task manager. Nothing interessant in log file, just the beginning of Psexec output, and nothing.

    Then I have tried different tools like RunasSpc (http://robotronic.de/runasspcFr.html) or Lsrunase (http://www.moernaut.com/default.aspx?item=lsrunase...) to get runas equivalent with password.
    With both I get an access denied or execution error...

    SSH:
    Launching a command using ssh client is working fine, and I have managed to use public key authentification so I have no password to enter. But with post-commit, it asks me to anwer yes to accept host connection on first time.

    @Tamara:
    Not sure that your poste can help me to manage this, but thanks
  • @Dan:

    Thanks for this. Saves loads of work updating local working copies for our Dev and QA environments.

    @Jies

    two issues we ran into were (1) paths and (2) permissions. Our setup includes subversion server 1.5.6 and apache 2.2 on Windows 2008 R2. Initially, we had the path as a mapped drive and the subversion and apache services running as the Local System account.

    So, we had something like:

    SET WORKING_COPY=X:\the\path\to\theworkingcopy

    Running it via CLI was fine, but commiting and executing via subsequent hook resulted in log message like

    Error resolving case of 'X:\the\path\to\theworkingcopy'

    So, I changed WORKING_COPY to use a UNC path such as:

    \\servername\DRIVELETTER$\the\path\to\theworkingcopy

    Still same problem, but I figured the services (for both needed to run with network privileges, so I changed the service "Log On As" to a domain account.

    One other issue I ran into was setting the domain for the services' "Log On As" user.  I used a domain user, but used a wildcard for the domain, e.g. ".\theuser"

    Then it just worked. Hope that helps you or someone.
  • @Greg:

    Glad the information helped!
  • Hi, All
    I need to launch this script automatically after changing a file so i'm not obliged to pass every time by right-click on the file and select SVN commit.

    I added this line to the batch script :

    svn commit -m "Ok." %WORKING_COPY%

    But , when i modify the file, the post-commit.bat didn't launch automatically

    What's wrong please.
  • how can i for svn comments only for .cpp files in pre-commit hook script
  • how can i force svn comments only for .cpp files in pre-commit hook script?
  • @shaggy:

    I don't know the answer to your pre-commit hook question.

    However, I'd recommend requiring comments for all commits. It's always best to make sure people are commenting all changes to the source--even if it's to just say things like:

    * Fixing spelling error in comment
    * Removed unneeded temp files

    It's just best to have documentation of each change.
  • Thanks for the info. I am running the script but receive the following when doing 'svn update' by using your debugging method:

    svn: E155004: Working copy 'C:\inetpub\wwwroot\Dashboard' locked
    svn: E200031: attempt to write a readonly database
    svn: E200031: attempt to write a readonly database
    svn: run 'svn cleanup' to remove locks (type 'svn help cleanup' for details)

    The working copy is not locked and I am able to run this via command line.

    I have checked permissions and even have the BAT file run as Administrator.

    Any suggestions?
  • @Scott:

    No clue as to what your problem might be. I've not seen that error.

    The only help I can provide is when I've seen problems in the past updating a working copy via a hook, I've just blown the working copy up and re-created it from scratch. That's always fixed issues for me in the past.

    Do keep in mind though that the BAT file probably won't run as Administrator--unless you're explicitly using a command line tool that's allowing your to escalate privileges.

    I'd recommend asking the question on an SVN mailing list or forum, if re-creating the working copy doesn't work for you.
  • Thanks Dan.

    I just figured it out. I changed the service so that it ran using an account with Administrator privileges. Once I restarted the service, everything worked great.
  • hello sir,

             how to integrate jira with tortoise svn ....what is the url need to be specified in url section?
  • @Shaggy:

    You need to look at Jira/Tortoise for help. This is not the right place.
  • Hi Sir,
       I have a post commit hook script that will print the newly added lines on the file specified by me in the server,when any new lines are added in the client side and committed using svnlook diff command...if i like to append a line say /** HI **/ on each modified area of the file on the client side how should i write post-commit hook script....thank you in advance
  • @dharsini:

    SVN hooks don't provide any way of doing that. I suppose you could write your own SVN client that interpreted the output from a hook and did some processing, but that would be a ton of work for something that's not a good idea in the first place.

    If you altered the client's working copy after a commit with some comments, you'd end up essentially creating an endless loop. The working copy would have changed, so you'd need to commit the changes again, which would create a new comment and the cycle would repeat.

    If the goal is to try an make sure the code is commented with changes, you might be able to do what pre-commit hook. From the docs:

      This is run when the transaction is complete, but before it is committed. Typically, this hook is used to protect against commits that are disallowed due to content or location (for example, your site might require that all commits to a certain branch include a ticket number from the bug tracker, or that the incoming log message is non-empty). The repository passes two arguments to this program: the path to the repository, and the name of the transaction being committed. If the program returns a non-zero exit value, the commit is aborted and the transaction is removed. If the hook program writes data to stderr, it will be marshalled back to the client.

      The Subversion distribution includes some access control scripts (located in the tools/hook-scripts directory of the Subversion source tree) that can be called from pre-commit to implement fine-grained write-access control. Another option is to use the mod_authz_svn Apache httpd module, which provides both read and write access control on individual directories (see the section called “Per-Directory Access Control”). In a future version of Subversion, we plan to implement access control lists (ACLs) directly in the filesystem.

    Either way, I suggest you posting on an SVN mailing list with whatever problem you're trying to solve. My guess is either someone has done it before or you'll get reasons why it's not a good idea.
  • Dear Dan,

    Can u please specify the Working copy either it is D:\Repositories\Name  or https://assd.asdas.com:8443/svn/Hi

    because my svn commands are not executing in batch files
  • Dear Dan,

    Can u please specify the Working of argument "%REV%" and from where it calls the value can u please specify the path
  • hi Dan,
    You helped me lot with this script for sending mail

    Can you also post script for trigger build in jenkins using post commit hook on subversion.
    It will be a great help
    Thanks in advance.
  • Hi Dan,

    Its been a wonderful article. However, I have a small query. Hope I will get it cleared from you. :-)

    In the above script, I think the email alert will be sent when the SVN update is done (By calculating the SVN diff). However, my requirement is that an email alert should be fired as and when any code check-in happens. It should try to find the difference between the previous and current versions. A plain email should be sent whenever a check-in happens.

    Can you please let me know what changes I need to make in the above script? Or the above script will suffice for my requirement?

    Looking forward to your reply.

    Thanks in advance,
    Harish.
  • @Harish:

    The script is part of the "post-commit" event, so it'll run every time a successful commit has been committed to the repository. When a successful commit occurs, any changes calculated by the diff will be e-mailed to you, so this should do what you need.
  • @Dan,

    Thanks for your quick reply.

    My modified script reads like below:

    @ECHO EFF

    SET REPOS=%1
    SET REV=%2

    SET DIR=D:\repos\test\hooks

    SET PATH=%PATH%;%DIR%;D:\utils

    SET SITENAME=Test Repository
    SET SMTP_SERVER=smtp.abc.com
    SET EMAIL_TO=abc@xyz.com
    SET EMAIL_FROM=abc@xyz.com
    SET SUBJECT=SVN Update - %SITENAME% - rev %REV% - %REPOS%

    ECHO The following changes were made to the code: > %DIR%/email.txt
    ECHO. >> %DIR%/email.txt

    sendEmail -s %SMTP_SERVER% -t %EMAIL_TO% -f %EMAIL_FROM% -u "%SUBJECT%" -o message-file=%DIR%/email.txt

    I have smtpEmail.exe under D:\utils

    Do I need to make any changes in the above script? I am not getting the email notification still. :-(

    For the variable PATH, do I need to give the path of my local system, like C:\Program Files\svn\bin.....? Please suggest.

    The email.txt file is created and its contents are below:
    The following changes were made to the code:

    Please show me the way ahead.

    Thanks in advance,
    Harish.
  • @Harish:

    See this post for debugging SVN Hooks in Windows:

    http://blog.pengoworks.com/index.cfm/2008/2/5/Debu...
  • Hi Dan,

    Thanks for your inputs. I rectified the small glitch in my code and am able to send the mails now. :-)

    I need your views on my next requirement. I need to send the list of files modified/checked-in in the body of the email. Something similar to below:

    Files Modified: svnrep.branch.Branch_1.src.com.test: Program1.java REVISION1 svnrepos

    Files Added: svnrep.branch.Branch_2.src.com.test: Program1.java REVISION2 svnrepos

    Can you please help me with this?
  • @Harish:

    Sorry, don't have any specific advice for you, but if you can figure out how to generate the content you want via a command line tool, you've got what you need to email the data to yourself!
  • Dan,

    Finally, I am able to get my post-commit hook UP and RUNNING. I am glad that I came across your blog. Thanks a lot again. :-)

    Cheers,
    Harish.
  • Dan,

    Any chance you have developed a script for pre-commit hook also? I need to implement a force commit with "specific format for the log message" before code check-in.
  • @Harish:

    Sorry, I don't have one. Ask around some SVN mailing lists and forums, I'm sure someone has some advice for you.
  • Hi Harish,

    My svn was deployed using apache and has SSL enabled. What else should I do to use your script?

    When I use TortoiseSVN to commit from my local PC, I don't receive any error messages. But the working copy on the server is not updated.

    When manually run the script using cmd, I got this:

    D:\path\to\hooks>post-commit
    Updating 'D:\path\to\working\copy':
    Revision 19.
    The system cannot find the path specified.
    The system cannot find the path specified.
    The system cannot find the path specified.
    The system cannot find the path specified.
    Apr 29 18:58:40 servername sendEmail[1532]: ERROR => Message body file speci
    fied [/hooks/email.txt] does not exist!

    But I can promise that the email.txt is there, which was created by previous manual run.

    I tried the debugging method you gave in another article and I got:

    D:\path\to\hooks>call "D:path\to\hooks\post-commit-run.bat"
      1>/hooks/post-commit.log 2>&1
    The system cannot find the path specified.

    What I did to the script was

    1. Edited the working copy path
    2. Edited the path to sendEmail.exe
    3. Edited Email perameters

    Did I miss something?

    Cheers,
  • is it possible to do it without the email?
  • Hi Dan,
    Thanks for post.
    I am new to this.

    I tried to do implement the above in my server, but when I commit my changes I see the commit is successful but the post-commit is taking a very long time just st for executing the svn log command and it fails with timeout. I am sure, I might be missing something.

    My subversion server is in my local only.

    Thanks in advance for the help

Comments for this entry have been disabled.