• Stars
    star
    3,925
  • Rank 10,565 (Top 0.3 %)
  • Language
    Go
  • License
    MIT License
  • Created about 5 years ago
  • Updated 10 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Fast and powerful Git hooks manager for any type of projects.

Build Status Coverage Status

Lefthook

The fastest polyglot Git hooks manager out there

Fast and powerful Git hooks manager for Node.js, Ruby or any other type of projects.

  • Fast. It is written in Go. Can run commands in parallel.
  • Powerful. It allows to control execution and files you pass to your commands.
  • Simple. It is single dependency-free binary which can work in any environment.

📖 Read the introduction post

Sponsored by Evil Martians

Install

With Go (>= 1.20):

go install github.com/evilmartians/lefthook@latest

With NPM:

npm install lefthook --save-dev

With Ruby:

gem install lefthook

Installation guide with more different installation instructions.

Usage

Lefthook is easy to use. Once you configure and setup you can forget that it even exists and rely on the magic underneath.

See:

  • Usage of lefthook CLI utility.
  • Configuration details for lefthook.yml
  • Wiki for other information.
  • Discussions if you want to ask a question, suggest a feature, or report a bug.

Why Lefthook

  • Parallel execution

Gives you more speed. Example

pre-push:
  parallel: true
  • Flexible list of files

If you want your own list. Custom and prebuilt examples.

pre-commit:
  commands:
    frontend-linter:
      run: yarn eslint {staged_files}
    backend-linter:
      run: bundle exec rubocop --force-exclusion {all_files}
    frontend-style:
      files: git diff --name-only HEAD @{push}
      run: yarn stylelint {files}
  • Glob and regexp filters

If you want to filter list of files. You could find more glob pattern examples here.

pre-commit:
  commands:
    backend-linter:
      glob: "*.rb" # glob filter
      exclude: "application.rb|routes.rb" # regexp filter
      run: bundle exec rubocop --force-exclusion {all_files}
  • Execute in sub-directory

If you want to execute the commands in a relative path

pre-commit:
  commands:
    backend-linter:
      root: "api/" # Careful to have only trailing slash
      glob: "*.rb" # glob filter
      run: bundle exec rubocop {all_files}
  • Run scripts

If oneline commands are not enough, you can execute files. Example.

commit-msg:
  scripts:
    "template_checker":
      runner: bash
  • Tags

If you want to control a group of commands. Example.

pre-push:
  commands:
    packages-audit:
      tags: frontend security
      run: yarn audit
    gems-audit:
      tags: backend security
      run: bundle audit
  • Support Docker

If you are in the Docker environment. Example.

pre-commit:
  scripts:
    "good_job.js":
      runner: docker run -it --rm <container_id_or_name> {cmd}
  • Local config

If you a frontend/backend developer and want to skip unnecessary commands or override something into Docker. Description.

# lefthook-local.yml
pre-push:
  exclude_tags:
    - frontend
  commands:
    packages-audit:
      skip: true
  • Direct control

If you want to run hooks group directly.

$ lefthook run pre-commit
  • Your own tasks

If you want to run specific group of commands directly.

fixer:
  commands:
    ruby-fixer:
      run: bundle exec rubocop --force-exclusion --safe-auto-correct {staged_files}
    js-fixer:
      run: yarn eslint --fix {staged_files}
$ lefthook run fixer
  • Optional output

If you don't want to see supporting information:

skip_output:
  - meta #(version and which hook running)
  - success #(output from runners with exit code 0)

Table of contents:

Guides

Migrate from

Examples

Benchmarks

Comparison list

Articles

More Repositories

1

mono

Free and open-source monospaced font from Evil Martians
1,978
star
2

terraforming-rails

Terraforming legacy Rails applications guides and tools
Ruby
724
star
3

oklch-picker

Color Picker for LCH
TypeScript
603
star
4

evil-seed

A Gem for creating partial anonymized dumps of your database using your app model relations.
Ruby
316
star
5

ruby-on-whales

Ruby on Whales example and templates
Ruby
267
star
6

fullstaq-ruby-docker

Docker image for Ruby build from Fullstaq packages based on Debian 10, 11, and 12.
Dockerfile
160
star
7

harmony

Harmony color palette
TypeScript
143
star
8

evil-client

Human-friendly DSL for writing HTTP(s) clients in Ruby
Ruby
104
star
9

activerecord-slotted_counters

Active Record extension providing slotted counters support
Ruby
96
star
10

fias

Ruby wrapper for the Russian FIAS database (Федеральная Информационная Адресная Система)
Ruby
82
star
11

chronicles-gql-martian-library

Ruby
71
star
12

chef-kubernetes

Google Kubernetes installer for ubuntu >= 16.04
Ruby
69
star
13

liquor

Liquor is a safe sandboxing compiling template language for Ruby
Ruby
59
star
14

figma-polychrom

Figma plugin for displaying the contrast level and font size recommendations according to the APCA method
TypeScript
58
star
15

graphql-connections

Additional implementations of cursor-based paginations for GraphQL Ruby gem.
Ruby
43
star
16

evil_chat

Code for "Evil Front: Modern Front-end in Rails" 3-part tutorial: https://evilmartians.com/chronicles/evil-front-part-1
Ruby
41
star
17

chef-prometheus-exporters

Ruby
38
star
18

chef-nginx

Chef Nginx recipes
Ruby
35
star
19

telephony

Evil Martians' telephony application that run our phone numbers
JavaScript
30
star
20

foundry

Foundry Compiler
OCaml
24
star
21

rubocoping-generator

Ruby application template to configure RuboCop with Standard and plugins
Ruby
14
star
22

furnace-xray

A visualizer for transformations of code in Static Single Assignment form based on the Furnace library.
CoffeeScript
11
star
23

cupid

Create, organize and send emails through ExactTarget SOAP API
Ruby
10
star
24

redis-proxy

Redis Proxy
Go
9
star
25

evil-struct

Nested structure with type constraints, based on the `dry-initializer` DSL
Ruby
9
star
26

omniauth-ebay-oauth

OmniAuth Strategy for eBay Apps (for using with eBay REST APIs)
Ruby
7
star
27

astro-typedoc

A tool for building astro-based documentation sites using Typescript types definitions and TSDocs.
JavaScript
7
star
28

zendesk

Proper Ruby wrapper around the Zendesk API
Ruby
6
star
29

catalyst-tutorial

Beyond Fashion Deep Learning With Catalyst post code
Python
6
star
30

monstro

Cult of Martians screensaver
Objective-C
5
star
31

foundry-lib

Foundry standard library and examples (public)
Fancy
5
star
32

github-tv

Forks your colleagues' open-source repos to your organization page
Ruby
4
star
33

chef-mdadm

mdadm recipe
Ruby
4
star
34

amplifr-node

JavaScript
3
star
35

helm-kubectl-docker

Dockerfile
2
star
36

homebrew-lefthook

Homebrew Formulae to lefthook
Ruby
2
star
37

kibana-logtrail

Kibana docker image with logtrail plugin.
Dockerfile
2
star
38

docker-curl

A simple docker image which contains curl (based on Alpine linux)
Dockerfile
1
star
39

charts

Public Helm charts
Smarty
1
star
40

foundry-web

Foundry website
JavaScript
1
star
41

gcloud-helm-docker

Deploy image for GKE with Helm & kubectl binaries.
Dockerfile
1
star
42

chef-consul-wrapper

Ruby
1
star
43

elasticsearch-k8s

1
star