diff --git a/src/Robo/Commands/Setup/SettingsCommand.php b/src/Robo/Commands/Setup/SettingsCommand.php index 5b7fbec6d..46f05825b 100644 --- a/src/Robo/Commands/Setup/SettingsCommand.php +++ b/src/Robo/Commands/Setup/SettingsCommand.php @@ -217,15 +217,16 @@ public function gitHooks() { protected function installGitHook($hook) { if ($this->getConfigValue('git.hooks.' . $hook)) { $this->say("Installing $hook git hook..."); - $source = $this->getConfigValue('git.hooks.' . $hook) . "/$hook"; - $dest = $this->getConfigValue('repo.root') . "/.git/hooks/$hook"; + $hook_source = $this->getConfigValue('git.hooks.' . $hook) . "/$hook"; + $project_hook_directory = $this->getConfigValue('repo.root') . "/.git/hooks"; $fs = new Filesystem(); - $source = rtrim($fs->makePathRelative($source, $dest), '/'); + $path_to_hook_source = rtrim($fs->makePathRelative($hook_source, $project_hook_directory), '/'); + $project_hook = $project_hook_directory . "/$hook"; $result = $this->taskFilesystemStack() ->mkdir($this->getConfigValue('repo.root') . '/.git/hooks') - ->remove($dest) - ->symlink($source, $dest) + ->remove($project_hook) + ->symlink($path_to_hook_source, $project_hook) ->stopOnFail() ->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERBOSE) ->run(); diff --git a/tests/phpunit/BltProject/SetupGitHooksTest.php b/tests/phpunit/BltProject/SetupGitHooksTest.php index 3b2fa5c32..e7a655027 100644 --- a/tests/phpunit/BltProject/SetupGitHooksTest.php +++ b/tests/phpunit/BltProject/SetupGitHooksTest.php @@ -16,8 +16,12 @@ class GitTasksTest extends BltProjectTestBase { public function testGitConfig() { $this->blt("blt:init:git-hooks"); $this->assertFileExists($this->sandboxInstance . '/.git'); - $this->assertFileExists($this->sandboxInstance . '/.git/hooks/commit-msg'); - $this->assertFileExists($this->sandboxInstance . '/.git/hooks/pre-commit'); + foreach ($this->config->get('git.hooks') as $hook => $path) { + $project_hook = $this->sandboxInstance . '/.git/hooks' . "/$hook"; + $this->assertFileExists($project_hook); + $source_hook = readlink($project_hook); + $this->assertFileExists($source_hook); + } } /**