Reputation: 1873
Is it possible to modify changed files(I want to tidy up xmls) in git pre-commit hook script? If yes, how to do it? Now I have such script:
files=`git diff --name-only --cached`
was_xml=false
for file in $files
do
extension="${file##*.}"
xml="xml"
if [ "$extension" = "$xml" ]
then
tmp_file=$file"_xmlint"
echo $tmp_file >> fuck
xmllint --format --encode utf8 $file > $tmp_file
rm $file
mv $tmp_file $file
git add $file
was_xml=true
fi
done
if $was_xml ; then
git commit -m 'Xml cleanup'
fi
But it doesn't work...
Upvotes: 1
Views: 973
Reputation: 4452
You probably want to look up clean
and smudge
( see http://git-scm.com/book/ch7-2.html ). You could do XML reformatting during the clean phase of staging a file.
Upvotes: 2