I have just set up a post-commit script in our subversion repository that triggers a build by requesting a hudson build URL.
This works fine as expected, however now I only want to trigger this build if the commit was to the trunk.
our post-commit script looks like this:
SET REPOS=%1
SET REV=%2
SET DIR=%REPOS%/hooks
SET PATH=%PATH%;%DIR%
wget http://circus-09:8080/job/UE/build?delay=0sec
How to I check that the commit was to the trunk?
Here's a quick code snippet, that outputs different messages when something in trunk changed or nothing has:
set repos=%~1
set rev=%~2
call :did_it_change "%repos%" "%rev%" "trunk"
if %ERRORLEVEL%==1 (
echo trunk changed
) else (
echo no changes in trunk
)
exit /B 0
:did_it_change
set repos=%~1
set rev=%~2
set dir=%~3
set found=0
for /F "delims=/" %%p in ('svnlook dirs-changed "%repos%" -r %rev% 2^>NUL') do call :check "%%p" "%dir%"
exit /B %found%
:check
set check_string=%~1
set must_match=%~2
if "$%check_string%" == "$%must_match%" set found=1
exit /B 0
Note, that :did_it_change function can be used with any repository root level subdirectory and not just trunk. Very useful, to detect new tags or branches. Also note, that the function can be called any number of times.
Note: This doesn't actually check if source files were changed or not - it simply checks if trunk is mentioned in the revisions changed directories list. It could be that the change was to the svn attributes of some directories or files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With