RETURN VALUE:
If my task has failed I will store this in the property ${task_failed} (failed=1).
Than I let the build fail by
<if>
<equals arg1="${task_failed}" arg2="1" />
<then>
<fail message="Task failed" />
</then>
</if>
COLLECTING UNCOMMITTED FILES:
Thanks to @cweiske I have created a task to collect my uncommitted files:
<target name="collect_uncommited_files">
<exec command="git diff-index --name-only --cached --diff-filter=ACMR HEAD" output="uncommitted_files.txt" />
<fileset id="uncommitted_files" dir="./" includesfiles="uncommited_files.txt">
</fileset>
</target>
I filter uncollected files with git diff-index and store the result into the external file uncommited_files.txt. Than I will load this file to create a fileset with my uncommitted files. (This would also work, when I store the result into a property and build my file set with include.)
In my case it seems to be a better way instead to copy all uncommitted files into a separate directory like done in @cweiske:checkout the files, because I don't want to move some MB around (I have to commit some very large files).