Closed HamidMolareza closed 2 days ago
@ARiYaNSEp0-0
If possible, please read about Git hooks and pre-commit. These tools help streamline the development process, keeping the project clean and organized by catching and fixing errors before the code is committed or pushed. For example, they can:
This is especially valuable in projects where multiple developers are collaborating.
It’s optional, and every developer needs to manually enable it after cloning the repository.
I use a setup-hooks.sh bash script for this, which is suitable for Linux systems.
I’ve also created an initial PowerShell script, but since I don’t use Windows, I can’t test it easily.
If you’re interested, you could test this script, and if everything works well, I’ll add it to this project and the Payadel/README project as well.
This script ensures that pre-commit, a Python module that can be installed via pip
, is installed. Then, it installs the necessary npm packages. Finally, it activates pre-commit and the required Git hooks.
How to execute powershell script?
Save the script file as setup-hooks.ps1
in the scripts
folder.
By default, PowerShell may restrict script execution. To allow it, you need to set an appropriate execution policy.
Open PowerShell as Administrator.
Run the following command to set the execution policy for the current user:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
Verify the policy:
Get-ExecutionPolicy -Scope CurrentUser
It should return RemoteSigned
.
Use the cd
command in PowerShell to navigate to the directory containing the script.
Run the script by typing:
.\setup-hooks.ps1
Thank you sir. I was a little bit familiar with git hooks and their use case but this explanation and links helped a lot.
I have two systems a windows 10 which is my main dev pc and linux mint xfce on another, for linux setup-hooks.sh is good ?
I have two systems a windows 10 which is my main dev pc and linux mint xfce on another, for linux setup-hooks.sh is good ?
This script should likely be suitable for any system that supports bash.
Fixed : I hadn't run npm install in the root directory until now to install commitlint. Sorry, that was my mistake! 😁
I ran the script, and when I try to commit after closing the COMMIT_MSG tab, I get this error:
Error: Cannot find module "@commitlint/config-conventional" from "C:\Users\lenovo\Desktop\QueraLens\.configs"
at resolveId (file:///C:/Users/lenovo/.cache/pre-commit/repohdbe0zem/node_env-default/Scripts/node_modules/commitlint-pre-commit-hook/node_modules/@commitlint/resolve-extends/lib/index.js:148:17)
at resolveConfig (file:///C:/Users/lenovo/.cache/pre-commit/repohdbe0zem/node_env-default/Scripts/node_modules/commitlint-pre-commit-hook/node_modules/@commitlint/resolve-extends/lib/index.js:132:20)
at file:///C:/Users/lenovo/.cache/pre-commit/repohdbe0zem/node_env-default/Scripts/node_modules/commitlint-pre-commit-hook/node_modules/@commitlint/resolve-extends/lib/index.js:93:26
at Array.reduce (<anonymous>)
at loadExtends (file:///C:/Users/lenovo/.cache/pre-commit/repohdbe0zem/node_env-default/Scripts/node_modules/commitlint-pre-commit-hook/node_modules/@commitlint/resolve-extends/lib/index.js:92:22)
at resolveExtends (file:///C:/Users/lenovo/.cache/pre-commit/repohdbe0zem/node_env-default/Scripts/node_modules/commitlint-pre-commit-hook/node_modules/@commitlint/resolve-extends/lib/index.js:76:28)
at load (file:///C:/Users/lenovo/.cache/pre-commit/repohdbe0zem/node_env-default/Scripts/node_modules/commitlint-pre-commit-hook/node_modules/@commitlint/load/lib/load.js:47:28)
at async main (file:///C:/Users/lenovo/.cache/pre-commit/repohdbe0zem/node_env-default/Scripts/node_modules/commitlint-pre-commit-hook/node_modules/@commitlint/cli/lib/cli.js:200:20) {
code: 'MODULE_NOT_FOUND'
}
Edit : also this is the output of setup-hooks.ps1
Starting setup-hooks script...
Installing 'commit-msg' pre-commit hook...
pre-commit installed at .git\hooks\commit-msg
Installing 'prepare-commit-msg' pre-commit hook...
pre-commit installed at .git\hooks\prepare-commit-msg
Installing 'pre-merge-commit' pre-commit hook...
pre-commit installed at .git\hooks\pre-merge-commit
Installing 'pre-push' pre-commit hook...
pre-commit installed at .git\hooks\pre-push
WARNING: Template for 'pre-rebase' hook not found.
No package.json found. Skipping npm dependency installation.
Setup-hooks script completed successfully.
Edit 2 : But I thought this script should install the dependencies listed in the root package.json, am I correct?
If everything is set up correctly, these hooks should run as follows:
main
or master
).You can modify this file whenever needed. For example, you can remove the document-oriented
hook.
In exceptional cases, you can also skip the execution of these hooks if necessary.
scripts/setup-hooks.ps1
file: