I would like to run a batch file via post-commit hook in Subversion. My problem is that I want to run it once for each file that has been committed but am unaware of a way to get the names of the committed files within the hook. I am able to run it for each file in the folder however when I am out of this test environment and actually using this feature there are far to many files and this would be very inefficient. Any ideas??
-
What exactly your hook script does? – bahrep Feb 14 '13 at 14:52
-
2Right now all it does is update date my working copy, however in order to use the code with the 3rd party software my company uses it needs to run a script, this script must be run on each file that has changed. I created a batch file which allows it to be run like this...myscript.bat changedfile.c from the command line...I would like to run my batch file for each changedfile – mgrenier Feb 14 '13 at 15:47
3 Answers
SVN passes to the hook two values, the path to the repository and the revision number that got generated.
Using this information you can ask to SVN the path changed in that revision and obtain the list of the added/modified files.

- 12,813
- 9
- 44
- 65
-
well good to know it can be done...could you offer any assistance on how to get the modified files? I have a script which does it to every file in the folder now, if you could show me the script to get the committed or modified file I would greatly appreciate it! :) – mgrenier Feb 14 '13 at 15:49
-
In the script just call svn log using the revision passed to it and you will get the full list of everything changed in the commit. – Davide Gualano Feb 14 '13 at 15:54
-
So I am able to get the names of the changed files now thanks, I am wondering if I can output them to a data structure such as an array so I can loop through them in order to call my batch file for each one? – mgrenier Feb 14 '13 at 18:11
-
I am using windows xp for testing but it will eventually be on a box with 2003 server. So I am just looking for a command line script to accomplish this I think I have everything I need except I am having issues getting the list of changed files in to a data structure that I can traverse. Thanks for your help. – mgrenier Feb 15 '13 at 14:56
-
From the command line you can launch svn log, and parse the output, but I suspect it would be very tricky. I would use a language like python for example, which has an excellent SVN library and will make the work a lot easier. – Davide Gualano Feb 15 '13 at 15:52
You made only one small mistake: filelist in transaction (server-side, as hooks executed on server) can be prepared easier (and without "noise" of log), than svn log -v
. It's svnlook
with subcommand changed
Sample for revision in repo (for transaction you'll use -t %TXN%
)
>svnlook.exe changed -r 31 Hello
U trunk/Hello.de.txt
U trunk/Hello.en.txt
U trunk/Hello.fr.txt
Hello
is path to repository root (not to Working Copy), output of command seems partially as output of svn st
, path to files are relative paths from repo-root

- 94,711
- 9
- 78
- 110
I was able to figure it out using batch and using some temporary text files to store some data. I had to do some processing to get just the name of the file in a variable, as that is what I needed as a parameter. This may not be the most efficient method but it accomplished my goal...
setlocal EnableDelayedExpansion
rem write a list of the changed files in a text file
"C:\svnpath\bin\svn.exe" log "C:\repo-path\project" -r %TXN% --verbose > "C:\path\changelist.txt"
rem write the list of all files into a text file
cd "C:\repo-path\project"
dir /b > "C:\path\filelist.txt"
rem loop through files
cd "C:\path"
for /F "delims=" %%i IN (filelist.txt) do (
rem search for file name in list of changed files, if found run batch file on it
find /i "%%i" changelist.txt > nul
echo %%i > "C:\path\temp.txt"
if not errorlevel 1 (
cd "C:\repo-path\project"
batchfile.bat %%i
)
)
rem delete temp files when finished
del "C:\path\filelist.txt"
del "C:\path\changelist.txt"
del "C:\path\changedfiles.txt"

- 1,409
- 3
- 21
- 45