Skip to content

Commit

Permalink
Cope with different line endings in .terraform-version
Browse files Browse the repository at this point in the history
Use `tr` to strip carriage returns from this file as it can cause failures in repositories with CRLF.

(remove log message changes)
  • Loading branch information
fractos committed Jul 11, 2024
1 parent 39d8c27 commit ffe5b01
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/tfenv-version-name.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function tfenv-version-name() {
&& log 'debug' "TFENV_VERSION_FILE retrieved from tfenv-version-file: ${TFENV_VERSION_FILE}" \
|| log 'error' 'Failed to retrieve TFENV_VERSION_FILE from tfenv-version-file';

TFENV_VERSION="$(cat "${TFENV_VERSION_FILE}" || true)" \
TFENV_VERSION="$(cat "${TFENV_VERSION_FILE}" || true | tr -d '\r')" \
&& log 'debug' "TFENV_VERSION specified in TFENV_VERSION_FILE: ${TFENV_VERSION}";

TFENV_VERSION_SOURCE="${TFENV_VERSION_FILE}";
Expand Down
4 changes: 2 additions & 2 deletions libexec/tfenv-resolve-version
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ if [ -z "${arg}" -a -z "${TFENV_TERRAFORM_VERSION:-""}" ]; then

if [ "${version_file}" != "${TFENV_CONFIG_DIR}/version" ]; then
log 'debug' "Version File (${version_file}) is not the default \${TFENV_CONFIG_DIR}/version (${TFENV_CONFIG_DIR}/version)";
version_requested="$(cat "${version_file}")" \
version_requested="$(cat "${version_file}" | tr -d '\r')" \
|| log 'error' "Failed to open ${version_file}";

elif [ -f "${version_file}" ]; then
log 'debug' "Version File is the default \${TFENV_CONFIG_DIR}/version (${TFENV_CONFIG_DIR}/version)";
version_requested="$(cat "${version_file}")" \
version_requested="$(cat "${version_file}" | tr -d '\r')" \
|| log 'error' "Failed to open ${version_file}";

# Absolute fallback
Expand Down

0 comments on commit ffe5b01

Please sign in to comment.