From 77ff2085e7e5684f684543d6e330acc840181d7c Mon Sep 17 00:00:00 2001 From: Sergii Kauk Date: Thu, 2 Jul 2020 16:04:13 +0200 Subject: [PATCH] Check if event is changing files To avoid commits with no files added which is the case when `affectedPaths()` return an empty array. See #50. --- addons/Spock/Commander.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/addons/Spock/Commander.php b/addons/Spock/Commander.php index e735ad8..3df83cb 100644 --- a/addons/Spock/Commander.php +++ b/addons/Spock/Commander.php @@ -92,7 +92,7 @@ public function config($config) */ public function shouldRunCommands() { - return $this->isEnvironmentAllowed() && $this->isEventAllowed(); + return $this->isEnvironmentAllowed() && $this->isEventAllowed() && $this->isEventAffectingFiles(); } /** @@ -114,6 +114,16 @@ protected function isEventAllowed() { return !in_array(get_class($this->event), array_get($this->config, 'ignore_events', [])); } + + /** + * Is event changing files? + * + * @return bool + */ + protected function isEventAffectingFiles() + { + return !empty($this->event->affectedPaths()); + } /** * Set the commands to be run.