From 71c4745e73ec18dabcbcc7c91fd42938b89ff7b5 Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Fri, 18 Nov 2016 10:26:34 -0500 Subject: [PATCH] Fixes #628: Allowing custom git hooks to be used. (#692) * Fixes #628: Allowing custom git hooks to be used. * Adding documentation. --- phing/build.yml | 8 ++++++++ phing/tasks/setup.xml | 28 ++++++++++++++++++++-------- readme/extending-blt.md | 18 ++++++++++++++++++ src/Update/Updater.php | 15 +++++++++++++++ src/Update/Updates.php | 6 +++++- template/blt/project.yml | 4 ---- 6 files changed, 66 insertions(+), 13 deletions(-) diff --git a/phing/build.yml b/phing/build.yml index 06dbf716f..f0a43adf0 100644 --- a/phing/build.yml +++ b/phing/build.yml @@ -69,6 +69,14 @@ drush: logoutput: yes verbose: ${blt.verbose} +git: + # The value of a hook should be the file path to a directory containing an + # executable file named after the hook. + # Changing a hook value to 'false' will disable it. + hooks: + pre-commit: ${blt.root}/scripts/git-hooks + commit-msg: ${blt.root}/scripts/git-hooks + multisite: # The docroot/sites/default directory is used by default. name: default diff --git a/phing/tasks/setup.xml b/phing/tasks/setup.xml index a42e4122e..1826c8208 100644 --- a/phing/tasks/setup.xml +++ b/phing/tasks/setup.xml @@ -228,16 +228,28 @@ - Removing ${repo.root}/.git/hooks, if it exists. - - - - Symlinking ${repo.root}/scripts/git-hooks to ${repo.root}/.git/hooks. - + + + + + + + + Symlinking ${repo.root}/scripts/git-hooks/pre-commit to ${git.hooks.pre-commit}/pre-commit + + + + + + + Symlinking ${repo.root}/scripts/git-hooks/commit-msg to ${git.hooks.pre-commit}/commit-msg + + + - Making git hooks executable. - + Making git hooks executable. + diff --git a/readme/extending-blt.md b/readme/extending-blt.md index 4439fa1ec..6265bed1d 100644 --- a/readme/extending-blt.md +++ b/readme/extending-blt.md @@ -86,6 +86,24 @@ More specifically, you can modify the build artifact in the following key ways: dir: ${deploy.dir}/docroot/profiles/contrib/lightning command: npm run install-libraries +### setup:* + +#### setup:git-hooks + +You may disable a git hook by setting its value under `git.hooks` to false: + + git: + hooks: + pre-commit: false + +You may use a custom git hook in place of BLT's default git hooks by setting its value under `git.hooks` to the directory path containing of the hook. The directory must contain an executable file named after the git hook: + + git: + hooks: + pre-commit: ${repo.root}/my-custom-git-hooks + +In this example, an executable file named `pre-commit` should exist in `${repo.root}/my-custom-git-hooks`. + ### tests:* #### tests:behat diff --git a/src/Update/Updater.php b/src/Update/Updater.php index ff9f63ab9..8371ab7ff 100644 --- a/src/Update/Updater.php +++ b/src/Update/Updater.php @@ -57,6 +57,13 @@ public function setRepoRoot($repoRoot) { $this->repoRoot = $repoRoot; } + /** + * @return ConsoleOutput + */ + public function getOutput() { + return $this->output; + } + /** * @return \Symfony\Component\Filesystem\Filesystem */ @@ -268,4 +275,12 @@ public function moveFile($source, $target, $overwrite = FALSE) { return FALSE; } + /** + * @param $filepath + */ + public function deleteFile($filepath) { + $abs_path = $this->getRepoRoot() . '/' . $filepath; + $this->getFileSystem()->remove($abs_path); + } + } diff --git a/src/Update/Updates.php b/src/Update/Updates.php index 0b0d5bf03..5fbcc984e 100644 --- a/src/Update/Updates.php +++ b/src/Update/Updates.php @@ -29,7 +29,7 @@ public function __construct(Updater $updater) { /** * @Update( * version = "8.5.1", - * description = "Removes deprecated features patch. Moves configuration files to blt subdirectory." + * description = "Removes deprecated features patch. Moves configuration files to blt subdirectory. Removes .git/hooks symlink." * ) */ public function update_851() { @@ -39,6 +39,10 @@ public function update_851() { $this->updater->moveFile('project.yml', 'blt/project.yml', TRUE); $this->updater->moveFile('project.local.yml', 'blt/project.local.yml', TRUE); $this->updater->moveFile('example.project.local.yml', 'blt/example.project.local.yml', TRUE); + + // Delete symlink to hooks directory. Individual git hooks are now symlinked, not the entire directory. + $this->updater->deleteFile('.git/hooks'); + $this->updater->getOutput()->writeln('.git/hooks was deleted. Please re-run setup:git-hooks to install git hooks locally.'); } } diff --git a/template/blt/project.yml b/template/blt/project.yml index e37a5aaa0..4c8f7414e 100644 --- a/template/blt/project.yml +++ b/template/blt/project.yml @@ -19,10 +19,6 @@ git: remotes: # Defining git remotes allows builds deployed via CI. - bolt8@svn-5223.devcloud.hosting.acquia.com:bolt8.git - # - radass4@svn-11692.prod.hosting.acquia.com:radass4.git - hooks: - pre-commit: true - commit-msg: true drush: # You can set custom project aliases in drush/site-aliases/aliases.drushrc.php.