Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ensure_single_trailing_newline() on macs. #16835

Merged
merged 1 commit into from
Apr 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 5 additions & 19 deletions contrib/utilities/indent_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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