wp-dev-lib icon indicating copy to clipboard operation
wp-dev-lib copied to clipboard

Install pre-commit script should overwrite the file.

Open kopepasah opened this issue 6 years ago • 4 comments

When running the pre-commit install script from wp-dev-lib, the pre-commit file in .git/hooks should be overwritten, if it exists. Currently, the script just fails and this is troublesome when trying to run the install script on the post-install-cmd script for Composer.

kopepasah avatar Dec 09 '19 18:12 kopepasah

Another option would be to check if the file already exists, but — IMO — running this script should take precedence and just overwrite the file.

kopepasah avatar Dec 09 '19 18:12 kopepasah

Projects can have multiple pre-commit scripts for things outside of what dev-lib does so we suggest ways for adding the dev-lib's pre-commit alongside existing scripts using husky (npm) and composer-git-hooks (PHP) in this section of readme.md. Would one of the suggested approaches work for your solution @kopepasah?

kasparsd avatar Dec 09 '19 19:12 kasparsd

Sure, any one of those method will work, but it still seems odd that a user can run this script (with the expectation that a pre-commit hook will install), but nothing gets installed. At that point, the user may not know what to do (depending on their level of expertise).

Is there a reason we do not want to overwrite the pre-commit script if a user invokes this install script?

kopepasah avatar Dec 09 '19 21:12 kopepasah

it still seems odd that a user can run this script (with the expectation that a pre-commit hook will install), but nothing gets installed.

💯Absolutely!

How about we add a prompt to ask if the file should be overwritten if it already exists? Like you said -- the purpose of this script is to setup pre-commit and it doesn't make sense that it silently fails. It should either report an error that a file already exists or ask if it should override it anyways.

kasparsd avatar Dec 10 '19 08:12 kasparsd