Iβve been using Apache Ant to write build scripts to automate the build and publishing of project. In order to make sure this script will run if and only if the repository contains no local modifications, I added the following target:
|
|
In order to activate it, add it as the first dependency of your main target. If you want to skip this target in order to test it, just run ant with the parameter -Ddebug
.
The idea behind this target is simple, first, I run βgit status -sβ and put the output inside the property git.status. If the repository is not modified, the command git status -s
is supposed to generate no output, thus the property git.status will be empty. Right after the execution of git status -s
, it checks the output of the command. If it is not empty, the script must fail with the message Changes detected in the repository.
The most important advantage of this simple target is that it uses only Git itself and the core tasks of Ant. No additional Ant tasks needed.