@@ -19,87 +19,90 @@ teammates then this is the tool you are looking for.
1919
20201 . Step into you existing package's directory (or create a new one with `git
2121 init && composer init`)
22- 2 . Run ` composer require 'sweetchuck/git-hooks' `
22+ 2 . Run ` composer require --dev 'sweetchuck/git-hooks' `
23233 . Then you have two option
24- 1 . Relay on the git hooks scripts which are shipped with this packag and
24+ 1 . Relay on Git hooks scripts which are shipped with this package and
2525 implement the logic in your ` ./.git-hooks ` file.
2626 2 . Or create a ` ./git-hooks ` directory and create Git hook files in it. (eg:
2727 ` ./git-hooks/pre-commit ` )
28284 . The deployment script will be automatically triggered by the
2929 ` post-install-cmd ` Composer event.
3030
3131
32- ## Example composer.json
33-
34- ``` JSON
35- {
36- "require" : {
37- "sweetchuck/git-hooks" : " dev-master"
38- },
39- "scripts" : {
40- "post-install-cmd" : [
41- " \\ Sweetchuck\\ GitHooks\\ Composer\\ Scripts::postInstallCmd"
42- ]
43- }
44- }
45- ```
46-
47-
4832## Configuration
4933
34+ Example composer.json file:
5035``` json
5136{
5237 "extra" : {
5338 "sweetchuck/git-hooks" : {
54- "core.hooksPath" : " git-hooks" ,
55- "symlink" : false
39+ "core.hooksPath" : " ./ git-hooks" ,
40+ "symlink" : true
5641 }
5742 }
5843}
5944```
6045
6146
62- ### Configuration - symlink
47+ ### Configuration - core.hooksPath
6348
64- Type: boolean
49+ Type: string
6550
66- Default value: false
51+ Default value: ` vendor/sweetchuck/git-hooks/git-hooks ` (dynamically detected)
6752
68- Copy or symlink Git hook files from the original location to the ` ./.git/hooks ` .
53+ If the Git version is >= v2.9 then this value will be used to set `git config
54+ core.hooksPath <FOO >`. If Git is older than 2.9 then the content of this
55+ directory will be symbolically linked or copied to ` ./.git/hooks ` directory.
6956
7057
71- ### Configuration - core.hooksPath
58+ ### Configuration - symlink
7259
73- Type: string
60+ Type: boolean
7461
75- Default value: git-hooks
62+ Default value: ` false `
7663
77- When this option is not empty then it allows to use the new feature of the Git
78- v2.9
64+ This configuration option will be used only if Git version is older than v2.9.
65+ Copy or symlink Git hook files from the original location (provided by the
66+ ` core.hooksPath ` configuration) to the ` ./.git/hooks ` .
7967
8068
8169## Example ./.git-hooks file
8270
83- The file below runs a Robo command corresponding the name of the current Git
84- hook.
71+ If you use the Git hooks script from this package
72+ (` vendor/sweetchuck/git-hooks/git-hooks ` ) you will need custom script which
73+ catches Git hooks add triggers something really useful.
8574
75+ Copy the content below into ` ./.git-hooks `
8676``` bash
8777#! /usr/bin/env bash
8878
89- # @todo Better detection for executables: php, composer.phar and robo.
90- robo=" $( composer config ' bin-dir' ) /robo"
79+ echo " BEGIN Git hook: ${sghHookName} "
80+
81+ function sghExit ()
82+ {
83+ echo " END Git hook: ${sghHookName} "
84+
85+ exit $1
86+ }
87+
88+ # @todo Better detection for executables: php, composer.phar.
89+ sghRobo=" $( composer config ' bin-dir' ) /robo"
90+
91+ test -s " ${sghBridge} .local" && . " ${sghBridge} .local"
92+
93+ sghTask=" githook:${sghHookName} "
9194
9295# Exit without error if "robo" doesn't exists or it has no corresponding task.
93- test -x " $robo " || exit 0
94- " $robo " help " githook: $sghHookName " 1> /dev/null 2>&1 || exit 0
96+ test -x " $sghRobo " || sghExit 0
97+ " ${sghRobo} " help " ${sghTask} " 1> /dev/null 2>&1 || sghExit 0
9598
9699if [ " $sghHasInput " = ' true' ]; then
97- " $robo " " githook: $sghHookName " $@ <<< $( < /dev/stdin ) || exit $?
100+ " $sghRobo " " ${sghTask} " $@ <<< $( < /dev/stdin ) || sghExit $?
98101else
99- " $robo " " githook: $sghHookName " $@ || exit $?
102+ " $sghRobo " " ${sghTask} " $@ || sghExit $?
100103fi
101104
102- exit 0
105+ sghExit 0
103106```
104107
105108
@@ -124,8 +127,3 @@ class RoboFile extends \Robo\Tasks
124127 }
125128}
126129```
127-
128-
129- ## Links
130-
131- * https://robo.li/
0 commit comments