From ebe15a2214010003bf55f72e93717059439552a6 Mon Sep 17 00:00:00 2001 From: joshschmitter <45405518+joshschmitter@users.noreply.github.com> Date: Thu, 23 Sep 2021 10:28:31 -0500 Subject: [PATCH] Clean up PATH after changing it (#56) Adding to the path without warning the user seems a little invasive. Save the original value and change it back after. --- hooks/terraform-fmt.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hooks/terraform-fmt.sh b/hooks/terraform-fmt.sh index ba8c3741..565f201c 100755 --- a/hooks/terraform-fmt.sh +++ b/hooks/terraform-fmt.sh @@ -5,6 +5,7 @@ set -e # OSX GUI apps do not pick up environment variables the same way as Terminal apps and there are no easy solutions, # especially as Apple changes the GUI app behavior every release (see https://stackoverflow.com/q/135688/483528). As a # workaround to allow GitHub Desktop to work, add this (hopefully harmless) setting here. +original_path=$PATH export PATH=$PATH:/usr/local/bin # Store and return last failure from fmt so this can validate every directory passed before exiting @@ -14,4 +15,7 @@ for file in "$@"; do terraform fmt -diff -check "$file" || FMT_ERROR=$? done +# reset path to the original value +export PATH=$original_path + exit ${FMT_ERROR}