Migrate pre-commit.entrypoint.sh to POSIX sh #5540
Reference in New Issue
Block a user
Delete Branch "posix-entrypoint"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The script was basically posix with a bashism.
POSIX sh is lighter and thus better.
@@ -1,5 +1,4 @@#!/usr/bin/env bashset -euo pipefailAny particular reason to remove
-euo pipefail?-euat least is supported by posix: https://pubs.opengroup.org/onlinepubs/007904875/utilities/set.htmlIn general one wants as much strictness and as little undefined behaviour as possible for shell scripts, which is why pretty much all well made shell scripts have
-euo pipefailset.I have explained all the changes in the commit messages but TLDR is that they were ineffective.
If you look below I've kept the
-eas it was the only relevant option.If one declares "this might go wrong" a person new to the codebase will look for "this" as a real possibility.
Thus removing it improves maintainability.
I am afraid I am going to have to disagree a little on the idea that the options are pointless.
Firstly, it is a broadly agreed shell scripting best practice to always enable such checks, and the argument that the checks are unlikely to catch errors at present is a sign that the checks have worked.
To be clear, you are absolutely correct that at present there is no real way at present for
undefinedorpipefailto be triggered.This is partly because during development when I made errors that triggered them, I rewrote the code to not trigger them, or allow for doing so.
Additionally, just because there are no hazards at present does not mean the script will not grow in future, and hazards detectable by the sets be introduced. It is unlikely someone will be careful enough to consider that having added pipes they should now add
pipefail, and with its absence we now have undefined behavior states. Much easier to just add it now, and its not like it has any performance cost. Another example: withoutundefineda later careless commit could easily remove the initial definition offiles_arg. The code would still work perfectly, but would be logically flawed and more open to later issues.Also, when I see a script with the options set I think to myself, "Great, I do not have to look for those types of errors as they are caught automatically". Whereas without them I have to be on guard for all kinds of undefined behavior myself.
Setting the options has no meaningful runtime cost or build time cost (save an extra ~10 bytes in the docker image ;D) and is both conventional and sensible defensive programming.
I do not think that so I did not communicate that thought anywhere.
I understand your position on it and see your points so I have reverted the change.
7358e5e7c2tod21e637e6eMigrate pre-commit.entrypoint.sh to POSIX shto WIP: Migrate pre-commit.entrypoint.sh to POSIX shLooks good, thanks!
57bde3783dto12eb772f15WIP: Migrate pre-commit.entrypoint.sh to POSIX shto Migrate pre-commit.entrypoint.sh to POSIX sh12eb772f15to7e246bcdbc7e246bcdbctobd6a2eda19