0

Need a little help with svn post-commit batch script. Here what I have:

post-commit.bat:

1. @ECHO OFF
2. cd D:\Subversion\...\hooks
3. SET OUTPUT = default
4. FOR /F "tokens=*" %%a in ('revision.bat') do ( SET OUTPUT=%%a )
5. findstr /m "Autobuild" D:\Subversion\...\db\revprops\0\%OUTPUT%
6. if %errorlevel%==0 (
7.   call website.bat
8. )

website.bat:

D:\Subversion\...\hooks\wget http://website.com/service-trigger

revision.bat:

svnlook youngest D:\Subversion\...

So, what is happening here is that

  1. After commit to repository, the script extracts the last revision number

  2. Uses that number to find a file in revision logs

  3. Try to find a particular string in that log

  4. If the particular string exists, fire some URL

My problem is that this script is executed when calling directly from cmd, but when SVN calls it, seems that something weird happens in line #5, because i do not get any error, but line #7 is never called.

I suspect that maybe i should run script as Administrator, but since I had never seriously programmed for Windows, I am not sure and I need some help

Boris Mocialov
  • 3,439
  • 2
  • 28
  • 55

1 Answers1

1

Spaces are significant in SET statements. In line 3, you are setting a variable "output " not "output"

Remove the spaces around the = in line 3 and after the %%a in line 4 (but cosmetic only here.)

Also - not clear whether ... is (omitted) or (parent-of-parent). If absolute filename contains spaces, "quote it"

Could also be that your starting directory is different for each invocation. The cd on line 2 changes the current directory on the D: drive, but does not affect the default drive. You'd need to execute D: to switch the default to drive D:. revision.bat on line 4 is relative to the default.

Magoo
  • 77,302
  • 8
  • 62
  • 84
  • ok, if all this is true (which i will be able to test after some hours) then why i managed to run this script directly? P.S. `...` omitted part – Boris Mocialov Jul 09 '13 at 16:49
  • 1
    It may be related to your starting directory. The `cd` command changes the `CURRENT` directory on `D:` - it does not change your logged (or current) drive, so you may get different results depending on what your current directory is. Whether `output` gets set or no depends on the presence of `revision.bat` in the current directory. If it does exist, then using your posted data, your `findstr` would be resolved to `findstr /m "Autobuild" D:\Subversion\...\db\revprops\0\svnlook youngest D:\Subversion\...` - which is probably not quite what you want. – Magoo Jul 09 '13 at 17:05
  • do you mean that if i have two drives, C, D, then if, while currently being on drive C, I run `cd D:\Subversion\...\hooks` and then call for example `revision.bat`which is on D, while I am still on C, then it will not work (and i am btw aware of that). So you are suggesting that somewhere after the line #2 I should call `D:` ? I actually thought about it, but did not try it – Boris Mocialov Jul 09 '13 at 17:16
  • that is exactly what was the problem, you can update your anwer to get accepted – Boris Mocialov Jul 10 '13 at 07:00