Skip to content

Commit

Permalink
Fixes #2633: Make git hook symlinks relative.
Browse files Browse the repository at this point in the history
  • Loading branch information
malikkotob committed Mar 16, 2018
1 parent 8c30d88 commit e35a750
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/Robo/Commands/Setup/SettingsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 6 additions & 2 deletions tests/phpunit/BltProject/SetupGitHooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/**
Expand Down

0 comments on commit e35a750

Please sign in to comment.