swellaby / rusty-hook

git hook manager, geared toward Rust projects
MIT License
205 stars 11 forks source link

Allow setting environment variables and map them with specific hook #180

Closed sudhirdhumal289 closed 2 years ago

sudhirdhumal289 commented 2 years ago

Description

Allow setting environment variables before executing command via hook.

Value

we will be able to execute command which are dependent on environment variable.

calebcartwright commented 2 years ago

Could you elaborate a bit on the specific use case you have in mind, and why you'd want/need this as opposed to the approaches that are already available today?

I'll take a guess and assume it's because you're trying to run some rather large commands like the one you mentioned in #181? I was originally going to ask why something like:

[hooks]
pre-commit = "FOO=bar cargo test ..."

wouldn't suffice for you, though similar question with the direct exports. Is it a matter of preference/perceived convenience or are you have issues getting the vars set in the context the commands are executed?

Also FWIW, that example is starting to hit the limits of what I'd want to try to specify inline in a toml key value. When the desired command(s) get large enough, I personally think folks would find it easier to utilize additional tooling like cargo make, or even adding a shell script to the repo (just be sure to make it executable on the git index) and set the toml file to

[hooks]
pre-commit = "sh your_committed_shell_script.sh"
sudhirdhumal289 commented 2 years ago

It will more of convenience, as and it will reduce the characters in command nothing more than that.

I already moved my code in shell script. Thnx,