Subversion's post-commit on windows with ANT
I was very disappointed when I installed subversion and noticed that the commit scripts were non-windows based within the windows-installer for subversion. Well I quickly got over that, and realized ANT had all my needs.
I searched the web for ANT Subversion Commit Scripts; and it returned some interesting articles, but no solid examples. So I quickly, researched ANT SVN plugins, then realized, I will be just executing SVN command line utilities to get the info I needed.
First, you can find these details almost anywhere, but quickly for you POST-COMMIT script to work, windows must need to know how to execute it, therefore, it must have a recognizable extension (like .bat). So to start out with rename the file that came with the repository to post-commit.bat
Second, subversion hooks run in a non-initialized dos command. That means you are not going to have any of the environment variables to your exposure.
The following is the code I have within my post script to execute my ANT post-commit.
Notice the -buildfile {filename} -Dproperty=value structure. This is how you run ALL ANT scripts. Go and search for ANT on the web if you need more details. Also notice that I'm capturing the output into a log file. If the log file doesn't get created, then you path-to-ant is wrong.
Now that I have my post-commit script trying to execute an ANT script; we need to have an ant script to execute. Our team has many repositories, so we are using the <import> directive in ANT to share code. But before I jump to the import I'm going to jump into the guts first.
The following is the shared code to work with the command line utilities of subversion. Notice svnget.all is the only target that has a depends attribute. This is to make this code as re-usable as possible. ANT allows (from the command line) to execute as many targets as needed. Or as i'll show you later, in our post-commit.build file we will have an empty target that has depends to execute the targets we want from this file.
Now that we have a shared code setup, we just need to create a post-commit.build file that looks like the following inside the hooks directory in your repository.
I searched the web for ANT Subversion Commit Scripts; and it returned some interesting articles, but no solid examples. So I quickly, researched ANT SVN plugins, then realized, I will be just executing SVN command line utilities to get the info I needed.
First, you can find these details almost anywhere, but quickly for you POST-COMMIT script to work, windows must need to know how to execute it, therefore, it must have a recognizable extension (like .bat). So to start out with rename the file that came with the repository to post-commit.bat
Second, subversion hooks run in a non-initialized dos command. That means you are not going to have any of the environment variables to your exposure.
The following is the code I have within my post script to execute my ANT post-commit.
e: cd \path-to-hooks "path-to-ant-executable" -buildfile post-commit.build -Dpath.repository=%1 -Drevision=%2 > post-commit.log
Notice the -buildfile {filename} -Dproperty=value structure. This is how you run ALL ANT scripts. Go and search for ANT on the web if you need more details. Also notice that I'm capturing the output into a log file. If the log file doesn't get created, then you path-to-ant is wrong.
Now that I have my post-commit script trying to execute an ANT script; we need to have an ant script to execute. Our team has many repositories, so we are using the <import> directive in ANT to share code. But before I jump to the import I'm going to jump into the guts first.
The following is the shared code to work with the command line utilities of subversion. Notice svnget.all is the only target that has a depends attribute. This is to make this code as re-usable as possible. ANT allows (from the command line) to execute as many targets as needed. Or as i'll show you later, in our post-commit.build file we will have an empty target that has depends to execute the targets we want from this file.
<?xml version="1.0" encoding="utf-8"?>
<project name="svn-email" default="build">
<target name="svnget.all" depends="svnget.author,svnget.info,svnget.changed,svnget.diff">
</target>
<target name="svnget.author">
<exec executable="svnlook" outputproperty="svnlook.author">
<arg value="author"/>
<arg value="${path.repository}"/>
<arg value="-r ${revision}"/>
</exec>
<echo message="${svnlook.author}" />
</target>
<target name="svnget.info">
<exec executable="svnlook" outputproperty="svnlook.info">
<arg value="info"/>
<arg value="${path.repository}"/>
<arg value="-r ${revision}"/>
</exec>
<echo message="${svnlook.info}" />
</target>
<target name="svnget.changed">
<exec executable="svnlook" outputproperty="svnlook.changed">
<arg value="changed"/>
<arg value="${path.repository}"/>
<arg value="-r ${revision}"/>
</exec>
<echo message="${svnlook.changed}" />
</target>
<target name="svnget.diff">
<exec executable="svnlook" outputproperty="svnlook.diff">
<arg value="diff"/>
<arg value="${path.repository}"/>
<arg value="-r ${revision}"/>
<arg value="--no-diff-deleted"/>
<arg value="--no-diff-added"/>
</exec>
<echo message="${svnlook.diff}" />
</target>
<target name="svn.email">
<property environment="svnlook.author" value=""/>
<property environment="svnlook.info" value=""/>
<property environment="svnlook.changed" value=""/>
<property environment="svnlook.diff" value=""/>
<mail mailhost="smtp.psu.edu"
tolist="l-adm-web@lists.psu.edu"
from="admissions@psu.edu"
subject="SVN ${path.repository} - ${svnlook.author}"
message="
${svnlook.info}
${svnlook.changed}
${svnlook.diff}
"/>
</target>
</project>
Now that we have a shared code setup, we just need to create a post-commit.build file that looks like the following inside the hooks directory in your repository.
<?xml version="1.0" encoding="utf-8"?> <project name="post-commit" default="build"> <import file="path-to-SharedHooks/svn-email.build"/> <target name="build" depends="svnget.all,svn.email"> </target> </project>
Added to my wiki: http://thecrumb.com/wiki/ant
ReplyDelete