From: David Wells Date: Tue, 2 Apr 2024 02:16:18 +0000 (-0400) Subject: Fix ensure_single_trailing_newline() on macs. X-Git-Tag: v9.6.0-rc1~397^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F16835%2Fhead;p=dealii.git Fix ensure_single_trailing_newline() on macs. I'm not sure exactly why mac's version of sed produces different output here but it is easy enough to use something simpler. Just check if the last character is a newline: if not, then append a newline character. --- diff --git a/contrib/utilities/indent_common.sh b/contrib/utilities/indent_common.sh index 16ffc31f99..da3d30708f 100644 --- a/contrib/utilities/indent_common.sh +++ b/contrib/utilities/indent_common.sh @@ -325,24 +325,10 @@ process_changed() # ensure_single_trailing_newline() { - f=$1 - - # Remove newlines at end of file - # Check that the current line only contains newlines - # If it doesn't match, print it - # If it does match and we're not at the end of the file, - # append the next line to the current line and repeat the check - # If it does match and we're at the end of the file, - # remove the line. - sed -e :a -e '/^\n*$/{$d;N;};/\n$/ba' $f >$f.tmpi - - # Then add a newline to the end of the file - # '$' denotes the end of file - # 'a\' appends the following text (which in this case is nothing) - # on a new line - sed -e '$a\' $f.tmpi >$f.tmp - - diff -q $f $f.tmp >/dev/null || mv $f.tmp $f - rm -f $f.tmp $f.tmpi + file="${1}" + + if test $(tail -c1 "$file") ; then + echo '' >> "$file" + fi } export -f ensure_single_trailing_newline