fix: correct order of checks in conditional for adding a missing newline (#1418)

We need to add trailing newlines to .tool-versions file before appending
a new version to the file. The order of the checks was wrong here as the
first check assumed the file existed, and the second checked if it did.
Switching them fixes the issue.

This fix was provided by @h3y6e

Fixes #1417
This commit is contained in:
Trevor Brown 2023-01-05 09:39:53 -05:00 committed by GitHub
parent 60d4494d5d
commit 4125d2b556
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -64,8 +64,8 @@ version_command() {
sed -i.bak -e "s|^$plugin_name .*$|$plugin_name ${resolved_versions[*]}|" "$file"
rm -f "$file".bak
else
# Add a trailing newline at the end of the file if missing
[[ -n "$(tail -c1 "$file")" && -f "$file" ]] && printf '\n' >>"$file"
# Add a trailing newline at the end of the file if missing and file present
[[ -f "$file" && -n "$(tail -c1 "$file")" ]] && printf '\n' >>"$file"
# Add a new version line to the end of the file
printf "%s %s\n" "$plugin_name" "${resolved_versions[*]}" >>"$file"