From d160f27efeff3dfe0fafc4e6da02dda561ac15b8 Mon Sep 17 00:00:00 2001 From: Topher Brown Date: Thu, 27 Jan 2022 01:01:46 -0500 Subject: [PATCH] precommit: `terraform fmt` makes changes on disk ### Issues Addressed Most of our pre-commit checks just make the changes that are rote, obvious changes. Not `terraform fmt`! And there's no reason for it, it's just someone decided to do it that way and the maintainers won't switch it back. Comment thread: https://github.com/gruntwork-io/pre-commit/issues/48 ### Summary of Changes I patched precommit to use the expected behavior. I included a shell file to add the patch so it's easy to stay up-to-date with upstream. ### Test Plan - Tested that precommit now automatically updates terraform files when using this branch for precommit. --- hooks/terraform-fmt.sh | 2 +- memfault-patch.sh | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100755 memfault-patch.sh diff --git a/hooks/terraform-fmt.sh b/hooks/terraform-fmt.sh index 565f201c..934ff2d4 100755 --- a/hooks/terraform-fmt.sh +++ b/hooks/terraform-fmt.sh @@ -12,7 +12,7 @@ export PATH=$PATH:/usr/local/bin FMT_ERROR=0 for file in "$@"; do - terraform fmt -diff -check "$file" || FMT_ERROR=$? + terraform fmt "$file" || FMT_ERROR=$? done # reset path to the original value diff --git a/memfault-patch.sh b/memfault-patch.sh new file mode 100755 index 00000000..57bcdb0f --- /dev/null +++ b/memfault-patch.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +sed -i -e 's/terraform fmt -diff -check/terraform fmt/' hooks/terraform-fmt.sh