Skip to content

Commit

Permalink
Fixes acquia#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 d5eb599 commit 6421bfa
Show file tree
Hide file tree
Showing 2 changed files with 17 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";
$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();
Expand Down
13 changes: 11 additions & 2 deletions tests/phpunit/BltProject/SetupGitHooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/**
Expand Down

0 comments on commit 6421bfa

Please sign in to comment.