#!/bin/bash -e
#
# Rewrite the last commit to remove any trailing whitespace
# in the new version of changed lines.
#
#
[[ -z $TRACE ]] || set -x
trap "rm -f $tmpf" 0
tmpf1=$TMP/$$.1.diff
tmpf2=$TMP/$$.2.diff
git show --binary >$tmpf1
perl -p -e 's/^(\+.*?)[ \t]+$/$1/;' <$tmpf1 >$tmpf2
if ! cmp -s $tmpf1 $tmpf2
then
	git apply --binary --index -R --whitespace=nowarn $tmpf1
#	git apply --index --whitespace=error $tmpf2
	git apply --binary --index --whitespace=strip $tmpf1
	EDITOR=true git commit --amend
else
	echo "No changes"
fi
