Question

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??

Was it helpful?

Solution 3

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"

OTHER TIPS

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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top