New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

git-hooks-toolkit

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

git-hooks-toolkit

Git Hooks Toolkit is a lightweight library to simplify the use of git hooks in a collaborative workflow. Git Hooks Toolkit can be used on any git repository and comes with a few added features like branch name, file name and commit message linting.

latest
Source
npmnpm
Version
0.0.2
Version published
Maintainers
1
Created
Source

Git Hooks Toolkit

Git Hooks Toolkit is a lightweight library to simplify the use of git hooks in a collaborative workflow.
Git Hooks Toolkit can be used on any git repository and comes with a few added features like branch name, file name and commit message linting.

Installation

NPX

Git Hooks Toolkit can be automatically installed with npx.

npx git-hooks-toolkit --init=maven

Git Hooks Toolkit needs to be wired on each collaborator local repository. Otherwise the hooks won't be automatically executed.

npx git-hooks-toolkit --wire

Manual installation

  • Copy the .git-hooks-toolkit folder in your project.
  • Run the installation script install.sh.
  • Create your config file from the documentation or use a predefined template.
    The installation script needs to be run on each collaborator local repository.

Usage

To configure different scripts to be run you need to place a git-hooks.yml in the .git-hooks-toolkit folder or at the root of your project. You can find configuration templates in the templates folder.

To bypass the hooks for a specific commit add --no-verify to your git command. Example: git commit -m 'yolo' --no-verify
More information on which git command support the --no-verify argument on Git

Set a pre-commit hook

pre_commit: npm run lint && npm run test

The pre-commit hook is run first, before you even type in a commit message. It’s used to inspect the snapshot that’s about to be committed, to see if you’ve forgotten something, to make sure tests run, or to examine whatever you need to inspect in the code. Git

Set a pre-push hook

pre_push: npm run lint && npm run test

The pre-push hook runs during git push, after the remote refs have been updated but before any objects have been transferred. You can use it to validate a set of ref updates before a push occurs. Git

Prevent commits to branches

no_commit_to: 
  branches:
    - master
    - develop
  message: 'Committing to the following branches is not allowed : master, develop'

Lint branch names

branchname_lint:
  regex: '^(develop|main|master|((feature|hotfix)/[a-zA-Z0-9\_]+))$'
  message: 'Commit aborted: branch name does not follow naming convention.'

Lint file names

filename_lint: 
  regex: '^[a-zA-Z\_\.\-]+$'
  message: 'Non-alphanumeric file names are not allowed.'

Lint commit messages

commit_lint: 
  regex: '^(add|fix|remove): .*'
  message: 'Commit message must contain a verb (ex: \"add: awesome feature\").'

Uninstall

NPX

To completely remove git-hooks-toolkit run:

npx git-hooks-toolkit --uninstall

To disable your custom git hooks in the current git repository but keep the git-hooks-toolkit config run:

npx git-hooks-toolkit --unwire

Manual

To completely remove git-hooks-toolkit run the script uninstall.sh.

To disable your custom git hooks in the current git repository but keep the git-hooks-toolkit config run the command git config --unset core.hooksPath.

Alternatives

Husky: https://github.com/typicode/husky

Pre-commit: https://github.com/pre-commit/pre-commit

FAQs

Package last updated on 05 Feb 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts