Skip to content

Commit 017adf4

Browse files
committed
- remove 'commit-msg' git hook for warden environments
- update readme file
1 parent 5b9b8a4 commit 017adf4

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ warden env exec php-fpm ./vendor/space48/magento2-code-quality/script/install.sh
8080
vendor/bin/grumphp git:init
8181
```
8282

83+
Create `.git` folder in warden:
84+
85+
(_You can mount .git volume from host to inside container instead, but `grumphp` only requires empty .git folder,
86+
no much sense in syncronizing all .git/* files adding even more overhead for mutagen._)
87+
```shell
88+
warden env exec php-fpm /bin/bash -c '[ -d .git ] || mkdir .git'
89+
```
90+
8391
Add configuration files to git:
8492
```shell
8593
git add ruleset.xml phpmd.xml .eslintrc .stylelintrc grumphp.yml
@@ -90,6 +98,7 @@ git add ruleset.xml phpmd.xml .eslintrc .stylelintrc grumphp.yml
9098
linters-init: # init linters on local machine
9199
warden env exec php-fpm chmod +x vendor/space48/magento2-code-quality/script/install.sh
92100
warden env exec php-fpm ./vendor/space48/magento2-code-quality/script/install.sh
101+
warden env exec php-fpm /bin/bash -c '[ -d .git ] || mkdir .git'
93102
vendor/bin/grumphp git:init
94103

95104
analyse: # analyses all code from starting commit hash to HEAD
@@ -112,7 +121,8 @@ Commit updated composer files, vendor folder, code-quality config files from the
112121
### Installation on any other Magento 2 project:
113122
1. add module `space48/code-quality` via Composer
114123
2. run `vendor/space48/code-quality/script/install.sh` script to copy necessary files and install npm packages
115-
3. run `vendor/bin/grumphp git:init` to update precommit hooks
124+
3. in `grumphp.yml` remove configs marked as `(remove on non warden environment)`
125+
4. run `vendor/bin/grumphp git:init` to update precommit hooks
116126

117127
## Configuration
118128

grumphp.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,22 @@ services:
2121
- '@grumphp.io'
2222
- '@GrumPHP\Configuration\Model\ProcessConfig'
2323
public: true
24+
## workaround to remove 'commit-msg' git hook (it may fail in warden if .git is not synced inside container)
25+
## (remove on non warden environment)
26+
GrumPHP\Console\Command\Git\InitCommand:
27+
class: \Space48\CodeQuality\Command\InitCommand
28+
arguments:
29+
- '@GrumPHP\Configuration\Model\HooksConfig'
30+
- '@grumphp.util.filesystem'
31+
- '@process_builder'
32+
- '@GrumPHP\Util\Paths'
33+
tags:
34+
- { name: 'console.command' }
2435

2536
## linter settings
2637
grumphp:
2738
git_hook_variables:
39+
## (remove on non warden environment)
2840
EXEC_GRUMPHP_COMMAND: 'warden env run --rm php-fpm'
2941
ignore_unstaged_changes: false
3042
fixer:

src/Command/InitCommand.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Space48\CodeQuality\Command;
4+
5+
use GrumPHP\Configuration\Model\HooksConfig;
6+
use GrumPHP\Process\ProcessBuilder;
7+
use GrumPHP\Util\Filesystem;
8+
use GrumPHP\Util\Paths;
9+
use Symfony\Component\Console\Input\InputInterface;
10+
use Symfony\Component\Console\Output\OutputInterface;
11+
12+
/**
13+
* Removes 'commit-msg' as it will not work inside warden if there is no .git folder there
14+
*/
15+
class InitCommand extends \GrumPHP\Console\Command\Git\InitCommand
16+
{
17+
public function __construct(
18+
HooksConfig $hooksConfig,
19+
Filesystem $filesystem,
20+
ProcessBuilder $processBuilder,
21+
Paths $paths
22+
) {
23+
parent::__construct($hooksConfig, $filesystem, $processBuilder, $paths);
24+
25+
$key = array_search('commit-msg', self::$hooks);
26+
if ($key !== false) {
27+
unset(self::$hooks[$key]);
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)