Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: evilmartians/lefthook
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.7.4
Choose a base ref
...
head repository: evilmartians/lefthook
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.7.5
Choose a head ref
  • 2 commits
  • 19 files changed
  • 1 contributor

Commits on Jul 22, 2024

  1. feat: use glob in exclude array (#777)

    * feat: use glob in exclude array
    
    * docs: update docs
    
    * fix: ignore empty array
    mrexox authored Jul 22, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    784335b View commit details
  2. 1.7.5: use globs in exclude when passing array

    mrexox committed Jul 22, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    mrexox Valentin Kiselev
    Copy the full SHA
    d7ae5f7 View commit details
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,10 @@

## master (unreleased)

## 1.7.5 (2024-07-22)

- feat: use glob in exclude array ([#777](https://github.com/evilmartians/lefthook/pull/777)) by @mrexox

## 1.7.4 (2024-07-19)

- fix: rollback packaging changes ([#776](https://github.com/evilmartians/lefthook/pull/776)) by @mrexox
48 changes: 27 additions & 21 deletions docs/configuration.md
Original file line number Diff line number Diff line change
@@ -561,7 +561,7 @@ pre-commit:

**Default: `false`**

> **Note**
> [!NOTE]
>
> Lefthook runs commands and scripts **sequentially** by default.

@@ -571,7 +571,7 @@ Run commands and scripts concurrently.

**Default: `false`**

> **Note**
> [!NOTE]
>
> Lefthook will return an error if both `piped: true` and `parallel: true` are set.

@@ -613,7 +613,7 @@ pre-push:
run: yarn test
```

> **Note**
> [!NOTE]
>
> If used with [`parallel`](#parallel) the output can be a mess, so please avoid setting both options to `true`.

@@ -786,7 +786,7 @@ pre-push:

Simply run `bundle exec rubocop` on all files with `.rb` extension excluding `application.rb` and `routes.rb` files.

> **Note**
> [!NOTE]
>
> `--force-exclusion` will apply `Exclude` configuration setting of Rubocop.

@@ -798,7 +798,9 @@ pre-commit:
rubocop:
tags: backend style
glob: "*.rb"
exclude: '(^|/)(application|routes)\.rb$'
exclude:
- config/application.rb
- config/routes.rb
run: bundle exec rubocop --force-exclusion {all_files}
```

@@ -1259,17 +1261,21 @@ pre-commit:

### `exclude`

You can provide a list of filenames or a regular expression to exclude some files from being passed to [`run`](#run) command.
For the `exclude` option two variants are supported:

If you pass a list of filenames, they must contain the full path of the file from the project root.
- A list of globs to be excluded
- A single regular expression (deprecated)

The regular expression is matched against full paths to files in the repo,
relative to the repo root, using `/` as the directory separator on all platforms.
File paths do not begin with the separator or any other prefix.

> [!NOTE]
>
> The regular expression is matched against full paths to files in the repo,
> relative to the repo root, using `/` as the directory separator on all platforms.
> File paths do not begin with the separator or any other prefix.

**Example**

Run Rubocop on staged files with `.rb` extension except for `application.rb`, `routes.rb`, and `rails_helper.rb` (wherever they are).
Run Rubocop on staged files with `.rb` extension except for `application.rb`, `routes.rb`, `rails_helper.rb`, and all Ruby files in `config/initializers/`.

```yml
# lefthook.yml
@@ -1278,11 +1284,15 @@ pre-commit:
commands:
lint:
glob: "*.rb"
exclude: '(^|/)(application|routes|rails_helper)\.rb$'
exclude:
- config/routes.rb
- config/application.rb
- config/initializers/*.rb
- spec/rails_helper.rb
run: bundle exec rubocop --force-exclusion {staged_files}
```

The same example using a list of filenames.
The same example using a regular expression.

```yml
# lefthook.yml
@@ -1291,14 +1301,10 @@ pre-commit:
commands:
lint:
glob: "*.rb"
exclude:
- config/routes.rb
- config/application.rb
- spec/rails_helper.rb
exclude: '(^|/)(application|routes|rails_helper|initializers/\w+)\.rb$'
run: bundle exec rubocop --force-exclusion {staged_files}
```


**Notes**

Be careful with the config file format's string quoting and escaping rules when writing regexps in it. For YAML, single quotes are often the simplest choice.
@@ -1367,7 +1373,7 @@ pre-commit:

**Default: `false`**

> **Note**
> [!NOTE]
>
> If you want to pass stdin to your command or script but don't need to get the input from CLI, use [`use_stdin`](#use_stdin) option instead.

@@ -1381,7 +1387,7 @@ Whether to use interactive mode. This applies the certain behavior:

**Default: `0`**

> **Note**
> [!NOTE]
>
> This option makes sense only when `parallel: false` or `piped: true` is set.
>
@@ -1464,7 +1470,7 @@ When you try to commit `git commit -m "bad commit text"` script `template_checke

### `use_stdin`

> **Note**
> [!NOTE]
>
> With many commands or scripts having `use_stdin: true`, only one will receive the data. The others will have nothing. If you need to pass the data from stdin to every command or script, please, submit a [feature request](https://github.com/evilmartians/lefthook/issues/new?assignees=&labels=feature+request&projects=&template=feature_request.md).

2 changes: 1 addition & 1 deletion docs/install.md
Original file line number Diff line number Diff line change
@@ -81,7 +81,7 @@ You can find the Swift wrapper plugin [here](https://github.com/csjones/lefthook
Utilize lefthook in your Swift project using Swift Package Manager:

```swift
.package(url: "https://github.com/csjones/lefthook-plugin.git", exact: "1.7.4"),
.package(url: "https://github.com/csjones/lefthook-plugin.git", exact: "1.7.5"),
```

Or, with [mint](https://github.com/yonaskolb/Mint):
14 changes: 10 additions & 4 deletions internal/lefthook/runner/filters/filters.go
Original file line number Diff line number Diff line change
@@ -80,15 +80,21 @@ func byExclude(vs []string, matcher interface{}) []string {

return vsf
case []interface{}:
excludeNames := make(map[string]struct{}, len(exclude))
if len(exclude) == 0 {
return vs
}

globs := make([]glob.Glob, 0, len(exclude))
for _, name := range exclude {
excludeNames[name.(string)] = struct{}{}
globs = append(globs, glob.MustCompile(name.(string)))
}

vsf := make([]string, 0)
for _, v := range vs {
if _, excluded := excludeNames[v]; !excluded {
vsf = append(vsf, v)
for _, g := range globs {
if ok := g.Match(v); !ok {
vsf = append(vsf, v)
}
}
}

2 changes: 1 addition & 1 deletion internal/version/version.go
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ import (
"strconv"
)

const version = "1.7.4"
const version = "1.7.5"

var (
// Is set via -X github.com/evilmartians/lefthook/internal/version.commit={commit}.
2 changes: 1 addition & 1 deletion packaging/npm-bundled/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@evilmartians/lefthook",
"version": "1.7.4",
"version": "1.7.5",
"description": "Simple git hooks manager",
"main": "bin/index.js",
"bin": {
2 changes: 1 addition & 1 deletion packaging/npm-installer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@evilmartians/lefthook-installer",
"version": "1.7.4",
"version": "1.7.5",
"description": "Simple git hooks manager",
"main": "bin/index.js",
"bin": {
2 changes: 1 addition & 1 deletion packaging/npm/lefthook-darwin-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lefthook-darwin-arm64",
"version": "1.7.4",
"version": "1.7.5",
"description": "The macOS ARM 64-bit binary for lefthook, git hooks manager.",
"preferUnplugged": false,
"repository": "https://github.com/evilmartians/lefthook",
2 changes: 1 addition & 1 deletion packaging/npm/lefthook-darwin-x64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lefthook-darwin-x64",
"version": "1.7.4",
"version": "1.7.5",
"description": "The macOS 64-bit binary for lefthook, git hooks manager.",
"preferUnplugged": false,
"repository": "https://github.com/evilmartians/lefthook",
2 changes: 1 addition & 1 deletion packaging/npm/lefthook-freebsd-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lefthook-freebsd-arm64",
"version": "1.7.4",
"version": "1.7.5",
"description": "The FreeBSD ARM 64-bit binary for lefthook, git hooks manager.",
"preferUnplugged": false,
"repository": "https://github.com/evilmartians/lefthook",
2 changes: 1 addition & 1 deletion packaging/npm/lefthook-freebsd-x64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lefthook-freebsd-x64",
"version": "1.7.4",
"version": "1.7.5",
"description": "The FreeBSD 64-bit binary for lefthook, git hooks manager.",
"preferUnplugged": false,
"repository": "https://github.com/evilmartians/lefthook",
2 changes: 1 addition & 1 deletion packaging/npm/lefthook-linux-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lefthook-linux-arm64",
"version": "1.7.4",
"version": "1.7.5",
"description": "The Linux ARM 64-bit binary for lefthook, git hooks manager.",
"preferUnplugged": false,
"repository": "https://github.com/evilmartians/lefthook",
2 changes: 1 addition & 1 deletion packaging/npm/lefthook-linux-x64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lefthook-linux-x64",
"version": "1.7.4",
"version": "1.7.5",
"description": "The Linux 64-bit binary for lefthook, git hooks manager.",
"preferUnplugged": false,
"repository": "https://github.com/evilmartians/lefthook",
2 changes: 1 addition & 1 deletion packaging/npm/lefthook-windows-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lefthook-windows-arm64",
"version": "1.7.4",
"version": "1.7.5",
"description": "The Windows ARM 64-bit binary for lefthook, git hooks manager.",
"preferUnplugged": false,
"repository": "https://github.com/evilmartians/lefthook",
2 changes: 1 addition & 1 deletion packaging/npm/lefthook-windows-x64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lefthook-windows-x64",
"version": "1.7.4",
"version": "1.7.5",
"description": "The Windows 64-bit binary for lefthook, git hooks manager.",
"preferUnplugged": false,
"repository": "https://github.com/evilmartians/lefthook",
18 changes: 9 additions & 9 deletions packaging/npm/lefthook/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lefthook",
"version": "1.7.4",
"version": "1.7.5",
"description": "Simple git hooks manager",
"repository": "https://github.com/evilmartians/lefthook",
"main": "bin/index.js",
@@ -20,14 +20,14 @@
},
"homepage": "https://github.com/evilmartians/lefthook#readme",
"optionalDependencies": {
"lefthook-darwin-arm64": "1.7.4",
"lefthook-darwin-x64": "1.7.4",
"lefthook-linux-arm64": "1.7.4",
"lefthook-linux-x64": "1.7.4",
"lefthook-freebsd-arm64": "1.7.4",
"lefthook-freebsd-x64": "1.7.4",
"lefthook-windows-arm64": "1.7.4",
"lefthook-windows-x64": "1.7.4"
"lefthook-darwin-arm64": "1.7.5",
"lefthook-darwin-x64": "1.7.5",
"lefthook-linux-arm64": "1.7.5",
"lefthook-linux-x64": "1.7.5",
"lefthook-freebsd-arm64": "1.7.5",
"lefthook-freebsd-x64": "1.7.5",
"lefthook-windows-arm64": "1.7.5",
"lefthook-windows-x64": "1.7.5"
},
"scripts": {
"postinstall": "node postinstall.js"
2 changes: 1 addition & 1 deletion packaging/pack.rb
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

require "fileutils"

VERSION = "1.7.4"
VERSION = "1.7.5"

ROOT = File.join(__dir__, "..")
DIST = File.join(ROOT, "dist")
2 changes: 1 addition & 1 deletion packaging/rubygems/lefthook.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |spec|
spec.name = "lefthook"
spec.version = "1.7.4"
spec.version = "1.7.5"
spec.authors = ["A.A.Abroskin", "Evil Martians"]
spec.email = ["lefthook@evilmartians.com"]

5 changes: 3 additions & 2 deletions testdata/exclude.txt
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ stdout 'excluded.txt lefthook.yml not-excluded.txt'
exec lefthook run -f regexp
stdout 'lefthook.yml not-excluded.txt'
exec lefthook run -f array
stdout 'lefthook.yml not-excluded.txt'
stdout 'not-excluded.txt'

-- lefthook.yml --
skip_output:
@@ -25,14 +25,15 @@ regexp:
commands:
echo:
run: echo {staged_files}
exclude: '^excluded.txt'
exclude: '^excluded\.[tx]+'

array:
commands:
echo:
run: echo {staged_files}
exclude:
- exclude.txt
- '*.yml'

-- not-excluded.txt --
sometext