From 6421bfa69fa8124709cdbd5a80aab2337450579c Mon Sep 17 00:00:00 2001 From: Malik Kotob Date: Fri, 16 Mar 2018 12:55:35 -0400 Subject: [PATCH] Fixes #2633: Make git hook symlinks relative. --- src/Robo/Commands/Setup/SettingsCommand.php | 11 ++++++----- tests/phpunit/BltProject/SetupGitHooksTest.php | 13 +++++++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/Robo/Commands/Setup/SettingsCommand.php b/src/Robo/Commands/Setup/SettingsCommand.php index 5b7fbec6da..b92391e6a2 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"; + $bltHook = $this->getConfigValue('git.hooks.' . $hook) . "/$hook"; + $projectHookDirectory = $this->getConfigValue('repo.root') . "/.git/hooks"; $fs = new Filesystem(); - $source = rtrim($fs->makePathRelative($source, $dest), '/'); + $pathToBltHook = rtrim($fs->makePathRelative($bltHook, $projectHookDirectory), '/'); + $projectHook = $projectHookDirectory . "/$hook"; $result = $this->taskFilesystemStack() ->mkdir($this->getConfigValue('repo.root') . '/.git/hooks') - ->remove($dest) - ->symlink($source, $dest) + ->remove($projectHook) + ->symlink($pathToBltHook, $projectHook) ->stopOnFail() ->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERBOSE) ->run(); diff --git a/tests/phpunit/BltProject/SetupGitHooksTest.php b/tests/phpunit/BltProject/SetupGitHooksTest.php index 3b2fa5c327..29d076ec54 100644 --- a/tests/phpunit/BltProject/SetupGitHooksTest.php +++ b/tests/phpunit/BltProject/SetupGitHooksTest.php @@ -16,8 +16,17 @@ 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'); + $hooksPath = $this->sandboxInstance . '/.git/hooks'; + $hookNames = [ + 'commit-msg', + 'pre-commit', + ]; + foreach ($hookNames as $hookName) { + $projectHook = $hooksPath . $hookName; + $this->assertFileExists($projectHook); + $bltHook = readlink($projectHook); + $this->assertFileExists($bltHook); + } } /**