You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Support Environment Variables for Hook Commands (#27)
Adds ability to configure environment variables to be set when invoking hook commands.
Variables are configured via hook "args" using the following argument pattern:
--hook:env:NAME=VALUE
feat: Add support for "--hook:error-on-output" in my-cmd-* hooks.
* Can exist anywhere in the arg list before a '--' argument
* re: Support for plain '--error-on-output' at first element
* Still works (currently)
* Is now deprecated and will be removed in a future version
chore: Use "/usr/bin/env" to invoke commands
* No-longer invokes the commands directly
* Makes it trivial to pass environment variables to commands
* Should not cause issues as /usr/bin/env was already vital
chore: Add "shellcheck source" declarations on dynamically sourced files
* Only files that were already modified for this PR were addressed
Breaking Change: For compatibility with file-based hooks, Repo-based hooks
no-longer ignore '--', or proceeding arguments, in the argument list.
However, to further match file-based logic, the first '--' will be consumed,
treating anything after it as OPTIONS to be passed to the hook command.
A set of git pre-commit hooks for Golang with support for multi-module monorepos, the ability to pass arguments to all hooks, and the ability to invoke custom go tools.
3
+
A set of git pre-commit hooks for Golang with support for multi-module monorepos, the ability to pass arguments and environment variables to all hooks, and the ability to invoke custom go tools.
4
4
5
5
Requires the [Pre-Commit.com](https://pre-commit.com) Hook Management Framework.
6
6
@@ -26,6 +26,11 @@ You can copy/paste the following snippet into your `.pre-commit-config.yaml` fil
26
26
# that Pre-Commit passes into the hook.
27
27
# For repo-based hooks, '--' is not needed.
28
28
#
29
+
# NOTE: You can pass environment variables to hooks using args with the
30
+
# following format:
31
+
#
32
+
# --hook:env:NAME=VALUE
33
+
#
29
34
# Consider adding aliases to longer-named hooks for easier CLI usage.
| alias | (optional) allows the hook to be referenced using an additional id when using `pre-commit run <hookid>` |
242
+
| name | (optional) override the name of the hook - shown during hook execution |
221
243
222
244
These are beneficial for a couple of reasons:
223
245
@@ -735,7 +757,7 @@ The alias will enable you to invoke the hook manually from the command-line when
735
757
736
758
Some tools, like `gofmt`, `goimports`, and `goreturns`, don't generate error codes, but instead expect the presence of any output to indicate warning/error conditions.
737
759
738
-
The my-cmd hooks accept an `--error-on-output` argument to indicate this behavior.
760
+
The my-cmd hooks accept a `--hook:error-on-output` argument to indicate this behavior.
739
761
740
762
Here's an example of what it would look like to use the my-cmd hooks to invoke `gofmt` if it wasn't already included:
741
763
@@ -748,10 +770,10 @@ _.pre-commit-config.yaml_
748
770
- id: my-cmd
749
771
name: go-fmt
750
772
alias: go-fmt
751
-
args: [ --error-on-output, gofmt, -l, -d]
773
+
args: [ gofmt, -l, -d, --hook:error-on-output]
752
774
```
753
775
754
-
**NOTE:** When used, the `--error-on-output` option **must** be the first argument.
776
+
**NOTE:** The plain `--error-on-output` option is now deprecated, but still supported, as long as it's the **very first** entry in the `args:` list.
0 commit comments