-
Notifications
You must be signed in to change notification settings - Fork 220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(remotes): add remotes and configs #609
Merged
mrexox
merged 3 commits into
evilmartians:master
from
NikitaCOEUR:feat/remote-to-remotes
Jan 22, 2024
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,26 +6,23 @@ Lefthook [supports](#config-file) YAML, JSON, and TOML configuration. In this do | |
- [Top level options](#top-level-options) | ||
- [`assert_lefthook_installed`](#assert_lefthook_installed) | ||
- [`colors`](#colors) | ||
- [`yellow`](#colors) | ||
- [`green`](#colors) | ||
- [`cyan`](#colors) | ||
- [`gray`](#colors) | ||
- [`red`](#colors) | ||
- [`no_tty`](#no_tty) | ||
- [`extends`](#extends) | ||
- [`min_version`](#min_version) | ||
- [`no_tty`](#no_tty) | ||
- [`rc`](#rc) | ||
- [`skip_output`](#skip_output) | ||
- [`source_dir`](#source_dir) | ||
- [`source_dir_local`](#source_dir_local) | ||
- [`remote` (Beta :test_tube:)](#remote) | ||
- [`rc`](#rc) | ||
- [`remote`](#remote--deprecated-show-remotes-instead) :warning: DEPRECATED use [`remotes`](#remotes) | ||
- [`git_url`](#git_url) | ||
- [`ref`](#ref) | ||
- [`config`](#config) | ||
- [Hook](#git-hook) | ||
- [`skip`](#skip) | ||
- [`only`](#only) | ||
- [`files`](#files-global) | ||
- [`config`](#config--deprecated-use-configs-like-specified-in-remotes) | ||
- [`remotes`](#remotes) | ||
- [`git_url`](#git_url-1) | ||
- [`ref`](#ref-1) | ||
- [`configs`](#configs) | ||
- [Git hook](#git-hook) | ||
- [`files` (global)](#files-global) | ||
- [`parallel`](#parallel) | ||
- [`piped`](#piped) | ||
- [`follow`](#follow) | ||
|
@@ -34,6 +31,11 @@ Lefthook [supports](#config-file) YAML, JSON, and TOML configuration. In this do | |
- [`scripts`](#scripts) | ||
- [Command](#command) | ||
- [`run`](#run) | ||
- [`{files}` template](#files-template) | ||
- [`{staged_files}` template](#staged_files-template) | ||
- [`{push_files}` template](#push_files-template) | ||
- [`{all_files}` template](#all_files-template) | ||
- [`{cmd}` template](#cmd-template) | ||
- [`skip`](#skip) | ||
- [`only`](#only) | ||
- [`tags`](#tags) | ||
|
@@ -48,6 +50,7 @@ Lefthook [supports](#config-file) YAML, JSON, and TOML configuration. In this do | |
- [`use_stdin`](#use_stdin) | ||
- [`priority`](#priority) | ||
- [Script](#script) | ||
- [`use_stdin`](#use_stdin) | ||
- [`runner`](#runner) | ||
- [`skip`](#skip) | ||
- [`only`](#only) | ||
|
@@ -288,7 +291,7 @@ Now any program that runs your hooks will have a tweaked PATH environment variab | |
|
||
## `remote` | ||
|
||
> :test_tube: This feature is in **Beta** version | ||
> :warning: DEPRECATED use [`remotes`](#remotes) setting | ||
|
||
You can provide a remote config if you want to share your lefthook configuration across many projects. Lefthook will automatically download and merge the configuration into your local `lefthook.yml`. | ||
|
||
|
@@ -308,6 +311,8 @@ This can be changed in the future. For convenience, please use `remote` configur | |
|
||
### `git_url` | ||
|
||
> :warning: DEPRECATED use [`remotes`](#remotes) setting | ||
|
||
A URL to Git repository. It will be accessed with privileges of the machine lefthook runs on. | ||
|
||
**Example** | ||
|
@@ -330,6 +335,8 @@ remote: | |
|
||
### `ref` | ||
|
||
> :warning: DEPRECATED use [`remotes`](#remotes) setting | ||
|
||
An optional *branch* or *tag* name. | ||
|
||
**Example** | ||
|
@@ -348,6 +355,8 @@ remote: | |
|
||
### `config` | ||
|
||
> :warning: DEPRECATED use [`remotes`](#remotes) setting | ||
|
||
**Default:** `lefthook.yml` | ||
|
||
An optional config path from remote's root. | ||
|
@@ -363,6 +372,107 @@ remote: | |
config: examples/ruby-linter.yml | ||
``` | ||
|
||
## `remotes` | ||
|
||
> :test_tube: This feature is in **Beta** version | ||
|
||
You can provide multiple remotes configs if you want to share yours lefthook configurations across many projects. Lefthook will automatically download and merge configurations into your local `lefthook.yml`. | ||
|
||
You can use [`extends`](#extends) related to the config file (not absolute paths). | ||
|
||
If you provide [`scripts`](#scripts) in a remote file, the [scripts](#source_dir) folder must be in the **root of the repository**. | ||
|
||
**Note** | ||
|
||
Configuration in `remotes` will be merged to configuration in `lefthook.yml`, so the priority will be the following: | ||
|
||
- `lefthook.yml` | ||
- `remotes` | ||
- `lefthook-local.yml` | ||
|
||
This can be changed in the future. For convenience, please use `remotes` configuration without any hooks configuration in `lefthook.yml`. | ||
|
||
### `git_url` | ||
|
||
A URL to Git repository. It will be accessed with privileges of the machine lefthook runs on. | ||
|
||
**Example** | ||
|
||
```yml | ||
# lefthook.yml | ||
|
||
remotes: | ||
- git_url: [email protected]:evilmartians/lefthook | ||
``` | ||
|
||
Or | ||
|
||
```yml | ||
# lefthook.yml | ||
|
||
remotes: | ||
- git_url: https://github.com/evilmartians/lefthook | ||
``` | ||
|
||
### `ref` | ||
|
||
An optional *branch* or *tag* name. | ||
|
||
**Example** | ||
|
||
```yml | ||
# lefthook.yml | ||
|
||
remotes: | ||
- git_url: [email protected]:evilmartians/lefthook | ||
ref: v1.0.0 | ||
``` | ||
|
||
> **Note** | ||
> | ||
> :warning: If you initially had `ref` option, ran `lefthook install`, and then removed it, lefthook won't decide which branch/tag to use as a ref. So, if you added it once, please, use it always to avoid issues in local setups. | ||
|
||
### `configs` | ||
|
||
**Default:** `- lefthook.yml` | ||
|
||
An optional array of config paths from remote's root. | ||
|
||
**Example** | ||
|
||
```yml | ||
# lefthook.yml | ||
|
||
remotes: | ||
- git_url: [email protected]:evilmartians/remote | ||
ref: v1.0.0 | ||
configs: | ||
- examples/ruby-linter.yml | ||
- examples/test.yml | ||
``` | ||
|
||
More complicated example. | ||
|
||
```yml | ||
# lefthook.yml | ||
|
||
remotes: | ||
- git_url: [email protected]:evilmartians/remote | ||
ref: v1.0.0 | ||
configs: | ||
- examples/ruby-linter.yml | ||
- examples/test.yml | ||
- git_url : https://github.com:example/repository | ||
configs: | ||
- lefthooks/pre_commit.yml | ||
- lefthooks/post_merge.yml | ||
- git_url : https://github.com:example2/repository2 | ||
ref: specific_branch | ||
configs: | ||
- example/pre-push.yml | ||
|
||
``` | ||
|
||
## Git hook | ||
|
||
Commands and scripts are defined for git hooks. You can defined a hook for all hooks listed in [this file](../internal/config/available_hooks.go). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
# Test `remote` config of lefthook. | ||
# Test `remotes` config of lefthook. | ||
# | ||
# # lefthook.yml | ||
# | ||
# remote: | ||
# git_url: [email protected]:evilmartians/lefthook | ||
# config: examples/remote/ping.yml | ||
# remotes: | ||
# - git_url: [email protected]:evilmartians/lefthook | ||
# configs: | ||
# - examples/remote/ping.yml | ||
# | ||
# $ lefthook run pre-commit | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we will extend the same things multiple times, and if files from different remotes have
extends
it will break here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I've tested this concern and I coundn't reproduce an error, because
extends
get replaced after merging each remote. That's fine. I will polish the PR a little bit and prepare it for the release.