From 6c44c6a1d33e539b6e02b842201a514bf3b23cea Mon Sep 17 00:00:00 2001 From: Nishant Arora Date: Thu, 7 Jul 2022 17:51:14 -0600 Subject: [PATCH 1/4] Fixing boolean parsing --- core/task.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/task.go b/core/task.go index 835a4a6..ff7eac5 100644 --- a/core/task.go +++ b/core/task.go @@ -27,7 +27,7 @@ type TaskResult struct { fixedOutput string } -var shouldStage = (os.Getenv("COMMITTER_SKIP_STAGE") == "") +var shouldNotStage, _ = strconv.ParseBool(os.Getenv("COMMITTER_SKIP_STAGE")) var autoFix, _ = strconv.ParseBool(os.Getenv("COMMITTER_AUTO_FIX")) var changedFiles, _ = exec.Command("git", "diff", "--diff-filter=ACMRTUXB", "--cached", "--name-only").Output() @@ -72,12 +72,12 @@ func (task Task) Execute(fix bool) TaskResult { if fixedOutput != "" { // If we have output, then we've corrected files - if shouldStage { - // Stage files by default automatically - task.stageRelevantFiles() - } else { + if shouldNotStage { // Explicitly fail the pre-commit hook so the files can be staged manually success = false + } else { + // Stage files by default automatically + task.stageRelevantFiles() } } } From 3a74635ae8313c82cbcf5e90fd9df24d1f47b141 Mon Sep 17 00:00:00 2001 From: Nishant Arora Date: Thu, 7 Jul 2022 17:54:08 -0600 Subject: [PATCH 2/4] Fixing Readme --- README.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7ba80f5..31d79e6 100644 --- a/README.md +++ b/README.md @@ -65,15 +65,14 @@ git push --follow-tags 1. Gusto engineers may [go/deploy-committer-with-cpe-chef](https://go/deploy-committer-with-cpe-chef). -## Autofix +## Environment Specific Configuration -Committer can auto-fix everything by default. set `export COMMITTER_AUTO_FIX=true # or 1, T, t` in your -`~/.profile` or equivalent dotfile. - -## Opting out of automatic staging - -Committer will stage auto-corrected files by default. In order to always leave auto-corrected files unstaged for manual staging, set `export COMMITTER_SKIP_STAGE=1` in your `~/.bashrc` or equivalent. +Set these values in your `~/.profile` or equivalent env vars `export =` +| Flag | Default | Expected | Description | +|---|---|---|---| +| COMMITTER_SKIP_STAGE | False | Truthy or Falsy | Committer will stage auto-corrected files by default. In order to always leave auto-corrected files unstaged for manual staging, set this value | +| COMMITTER_AUTO_FIX | False | Truthy or Falsy | Committer can auto-fix code formatting in staged files by default | ## Best-practices ### Purely Functional Pre-Commit Hooks From b411b1055d4e267553da262dd3cc2bc37557102b Mon Sep 17 00:00:00 2001 From: Nishant Arora Date: Fri, 8 Jul 2022 11:59:31 -0600 Subject: [PATCH 3/4] Fixing comment --- core/task.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/task.go b/core/task.go index ff7eac5..160cedd 100644 --- a/core/task.go +++ b/core/task.go @@ -73,10 +73,10 @@ func (task Task) Execute(fix bool) TaskResult { if fixedOutput != "" { // If we have output, then we've corrected files if shouldNotStage { - // Explicitly fail the pre-commit hook so the files can be staged manually + // Fail the pre-commit hook so the files can be staged manually success = false } else { - // Stage files by default automatically + // Stage files automatically otherwise. task.stageRelevantFiles() } } From ee9cd3c421ac11e8c028ce01fadf3240176d1076 Mon Sep 17 00:00:00 2001 From: Nishant Arora Date: Fri, 8 Jul 2022 12:04:13 -0600 Subject: [PATCH 4/4] Fix tests --- core/task_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/task_test.go b/core/task_test.go index a4dfdd1..a7f45ad 100644 --- a/core/task_test.go +++ b/core/task_test.go @@ -259,9 +259,9 @@ func TestExecuteFixFailureWithFixCommand(t *testing.T) { } func TestExecuteFixSuccessWithFixCommandShouldNotStage(t *testing.T) { - origShouldStage := shouldStage - shouldStage = false - defer func() { shouldStage = origShouldStage }() + origShouldStage := shouldNotStage + shouldNotStage = true + defer func() { shouldNotStage = origShouldStage }() stubExecCommand( []byte(`Linted: app/one.rb