You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+37-10Lines changed: 37 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,33 +5,51 @@
5
5
[![Packagist][badge-packagist]][link-packagist]
6
6
[![Download][badge-downloads]][link-packagist]
7
7
8
-
> Manage git hooks easily in your composer configuration. This package makes it easy to implement a consistent project-wide usage of git hooks. Specifying hooks in the composer file makes them available for every member of the project team. This provides a consistent environment and behavior for everyone which is great.
8
+
> Manage git hooks easily in your composer configuration. This command line tool makes it easy to implement a consistent project-wide usage of git hooks. Specifying hooks in the composer file makes them available for every member of the project team. This provides a consistent environment and behavior for everyone which is great. It is also possible to use to manage git hooks globally for every repository on your computer. That way you have a reliable set of hooks crafted by yourself for every project you choose to work on.
9
9
10
10
## Install
11
11
12
12
Add a `hooks` section to the `extra` section of your `composer.json` and add the hooks there. The previous way of adding hooks to the `scripts` section of your `composer.json` is still supported, but this way is cleaner if you have many scripts.
This installs the `cghooks` binary to your `vendor/bin` folder. If this folder is not in your path, you will need to preface every command with `vendor/bin/`.
34
42
43
+
### Global support
44
+
45
+
You can also install it globally. This feels much more natural when `cghooks` is used with the newly added support for managing global git hooks.
46
+
47
+
```sh
48
+
composer global require --dev brainmaestro/composer-git-hooks
49
+
```
50
+
51
+
All commands have global support (besides testing the hooks. Still requires being in the directory with the `composer.json` file).
52
+
35
53
### Optional Configuration
36
54
37
55
#### Shortcut
@@ -63,7 +81,7 @@ Add the following events to your `composer.json` file. The `cghooks` commands wi
63
81
64
82
## Usage
65
83
66
-
All the following commands have to be run in the same folder as your `composer.json` file.
84
+
All the following commands have to be run either in the same folder as your`composer.json` file or by specifying the `--git-dir` option to point to a folder with a`composer.json` file.
67
85
68
86
### Adding Hooks
69
87
@@ -78,10 +96,14 @@ to add all the valid git hooks that have been specified in the composer config.
78
96
79
97
The `lock` file contains a list of all added hooks.
80
98
99
+
If the `--global` flag is used, the hooks will be added globally, and the global git config will also be modified. If no directory is provided, there is a fallback to the current `core.hooksPath` in the global config. If that value is not set, it defaults to `$COMPOSER_HOME` (this specific fallback only happens for the `add` command). It will fail with an error if there is still no path after the fallbacks.
100
+
81
101
### Updating Hooks
82
102
83
103
The update command which is run with `cghooks update` basically ignores the lock file and tries to add hooks from the composer lock. This is similar to what the `--force` option for the `add` command did. This command is useful if the hooks in the `composer.json` file have changed since the first time the hooks were added.
84
104
105
+
This works similarly when used with `--global` except that there is no fallback to `$COMPOSER_HOME` if no directory is provided.
106
+
85
107
### Removing Hooks
86
108
87
109
Hooks can be easily removed with `cghooks remove`. This will remove all the hooks that were specified in the composer config.
@@ -94,6 +116,8 @@ Hooks can also be removed by passing them as arguments. The command `cghooks rem
94
116
95
117
**CAREFUL**: If the lock file was tampered with or the force option was used, hooks that already existed before using this package, but were specified in the composer scripts config will be removed as well. That is, if you had a previous `pre-commit` hook, but your current composer config also has a `pre-commit` hook, this option will cause the command to remove your initial hook.
96
118
119
+
This also does not have a fallback to `$COMPOSER_HOME` if no directory is provided when used with `--global`.
120
+
97
121
### Listing hooks
98
122
99
123
Hooks can be listed with the `cghooks list-hooks` command. This basically checks composer config and list the hooks that actually have files.
@@ -102,9 +126,12 @@ Hooks can be listed with the `cghooks list-hooks` command. This basically checks
0 commit comments