Closed Sanguigui closed 6 years ago
The pre-commit command, on most tasks, only checks the staged files that are about to be commited.
Yes, I staged a file with obvious errors that you can see listed when I ran ./vendor/bin/grumphp run
first.
The diff is given to the pre-commit command but the phpcs command isn't run in this case.
So what does git diff -r -p -m -M --full-index --staged
output? Because, by the looks of it, the pre-commit command isn't even executing PHPCS due to no PHP files being staged (otherwise it would output the command being executed, as you can see in the run command output).
git diff -r -p -m -M --full-index --staged
outputs:
diff --git a/auraengine/app/ServiceHelpers/Exports/ClusterExport.php b/auraengine/app/ServiceHelpers/Exports/ClusterExport.php
index e29fff66f4d7b798dc5b4e9107989da2648e95b6..9fcc5ee37a0921b49208ed8537fc735727a7aaf2 100755
--- a/auraengine/app/ServiceHelpers/Exports/ClusterExport.php
+++ b/auraengine/app/ServiceHelpers/Exports/ClusterExport.php
@@ -46,5 +46,6 @@ class ClusterExport extends Base
}
}
)->download('xlsx');
+ echo 'sth';;;
}
}
And when I commit these changes I get:
GrumPHP detected a pre-commit command.
GrumPHP is sniffing your code!
Running task 1/2: Phpcs... ✔
Running task 2/2: PhpMd... ✔
GrumPHP detected a commit-msg command.
GrumPHP is sniffing your code!
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▄▄▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
▄▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
▄▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
▐█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
▀█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
▀▀▓▓▓▓▓▓▓▓▓▓▓▓█▀▀▀▀▀▀▀▀▀▀▀▀▀▀████████████▄
▄████████▀▀▀▀▀ ██████████
███████▀ ██████▀
▐████ ██▌ ██ ████▌
▐█▌ ███
█▌ ▄▄ ▄▄ ▐███
███ ▄▄▄▄▄▄▄▄▄▄▄▄ ▐███
██▄ ▐███████████████████████████
█▀█████████▌▀▀▀▀▀▀▀▀▀██████████▌▐
███████████▄▄▄▄▄▄▄███████████▌
▐█████████████████████████████
█████████████████████████████
██ █████████████████████▐██▀
▀ ▐███████████████████▌ ▐▀
████▀████████▀▐███
▀█▌ ▐█████ ▐█▌
██▀ ▐▀
_ _ _ _ _
/ \ | | | __ _ ___ ___ __| | |
/ _ \ | | | / _` |/ _ \ / _ \ / _` | |
/ ___ \| | | | (_| | (_) | (_) | (_| |_|
/_/ \_\_|_| \__, |\___/ \___/ \__,_(_)
|___/
Hi @Sanguigui,
As you can see in the -vvv
log, no files are shown in the output of the git diff command:
[2018-08-21 09:15:37] GrumPHP.DEBUG: Repository created (git dir: "/var/www/auraengine.io/.git", working dir: "/var/www/auraengine.io") [] []
[2018-08-21 09:15:37] GrumPHP.INFO: run command: diff "-r -p -m -M --full-index --staged" [] []
[2018-08-21 09:15:37] GrumPHP.DEBUG: last command (diff) duration: 47.46ms [] []
[2018-08-21 09:15:37] GrumPHP.DEBUG: last command (diff) return code: 0 [] []
[2018-08-21 09:15:37] GrumPHP.DEBUG: last command (diff) output: [] []
This means that the files you are trying to validate are not properly staged while running the command. The first line displays that .git is created in the repository. Is it possible that you are running those commands on a virtualized environment in which the .git files are not being synced?
Hi @veewee ,
Yes I run grumPHP in a Vagrant box and my .git files are not in my synced folder. Is there a fix related to this type of configuration?
And what's happening when I run grumPHP in this type of configuration compared to a local project ?
Hi @Sanguigui,
Since this issue is related to your setup, fixing the issue is up to you.
GrumPHP requires the git repository to list the files and the changes. Those git commands are being used to run the tasks on. There are 2 options:
Hi @veewee ,
After double checking with the team here's the configuration:
Here's the pre-commit git hook:
#!/bin/sh
#
# Run the hook command.
# Note: this will be replaced by the real command during copy.
#
# Fetch the GIT diff and format it as command input:
DIFF=$(git -c diff.mnemonicprefix=false --no-pager diff -r -p -m -M --full-index --no-color --staged | cat)
# Output the DIFF
echo ${DIFF};
# Run GrumPHP
(cd "auraengine/" && printf "%s\n" "${DIFF}" | exec '/var/www/auraengine.io/auraengine/vendor/bin/grumphp' 'git:pre-commit' '--skip-success-output' '-vvv')
I added an echo
and a -vvv
to see what happens and as you can see below, the diff is given to grumphp when commiting inside the Vagrant box:
git add -A && git commit -m "test"
diff --git a/auraengine/app/Http/Controllers/Auth/test.php b/auraengine/app/Http/Controllers/Auth/test.php index 72e7dc2dd6c0bf8540e32ecc694c5a1e0a55624a..449c3893984f68fd97698fc2e9210cf3b16f7cbb 100644 --- a/auraengine/app/Http/Controllers/Auth/test.php +++ b/auraengine/app/Http/Controllers/Auth/test.php @@ -1,3 +1,3 @@ <?php -echo 'truc';;; \ No newline at end of file +echo 'truc';; \ No newline at end of file
[2018-09-04 06:00:09] GrumPHP.DEBUG: Repository created (git dir: "/var/www/auraengine.io/.git", working dir: "/var/www/auraengine.io") [] []
GrumPHP detected a pre-commit command.
GrumPHP is sniffing your code!
Running task 1/1: Phpcs... ✔
GrumPHP detected a commit-msg command.
GrumPHP is sniffing your code!
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▄▄▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
▄▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
▄▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
▐█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
▀█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
▀▀▓▓▓▓▓▓▓▓▓▓▓▓█▀▀▀▀▀▀▀▀▀▀▀▀▀▀████████████▄
▄████████▀▀▀▀▀ ██████████
███████▀ ██████▀
▐████ ██▌ ██ ████▌
▐█▌ ███
█▌ ▄▄ ▄▄ ▐███
███ ▄▄▄▄▄▄▄▄▄▄▄▄ ▐███
██▄ ▐███████████████████████████
█▀█████████▌▀▀▀▀▀▀▀▀▀██████████▌▐
███████████▄▄▄▄▄▄▄███████████▌
▐█████████████████████████████
█████████████████████████████
██ █████████████████████▐██▀
▀ ▐███████████████████▌ ▐▀
████▀████████▀▐███
▀█▌ ▐█████ ▐█▌
██▀ ▐▀
_ _ _ _ _
/ \ | | | __ _ ___ ___ __| | |
/ _ \ | | | / _` |/ _ \ / _ \ / _` | |
/ ___ \| | | | (_| | (_) | (_) | (_| |_|
/_/ \_\_|_| \__, |\___/ \___/ \__,_(_)
|___/
[feature/static-analysis-linting a89bab7a] test
1 file changed, 1 insertion(+), 1 deletion(-)
So it looks like the diff is given ?
0.14.1
When I run
./vendor/bin/grumphp run
, my phpcs tasks is well executed and I got the errors I'm expecting but when I run./vendor/bin/grumphp git:pre-commit
the phpcs task is green and 'All good face' is there.My configuration
The composer.json file
My actions
With the
./vendor/bin/grumphp run -vvv
command without the whole project listing:with
./vendor/bin/grumphp git:pre-commit -vvv
:I don't know why it doesn't run the same command on the commit