Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Fixes #1657: PHP shebang echoed during commit message validation. #1658

Merged
merged 3 commits into from
Jun 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function initialize() {
$this->drupalPhpcsStandard = $this->bltRoot . '/vendor/drupal/coder/coder_sniffer/Drupal/ruleset.xml';
$this->phpcsPaths = [
$this->bltRoot . '/bin/blt',
$this->bltRoot . '/bin/blt-robo',
$this->bltRoot . '/bin/blt-robo.php',
$this->bltRoot . '/bin/blt-robo-run.php',
$this->bltRoot . '/RoboFile.php',
$this->bltRoot . '/src/Robo',
Expand Down
80 changes: 5 additions & 75 deletions bin/blt
Original file line number Diff line number Diff line change
@@ -1,81 +1,11 @@
#!/usr/bin/env php
<?php
/**
* @file
*/

$repo_root = find_repo_root();
$autoload = require_once $repo_root . '/vendor/autoload.php';
if (!isset($autoload)) {
print "Unable to find autoloader for BLT\n";
exit(1);
}

require_once __DIR__ . '/blt-robo-run.php';

/**
* Finds the root directory for the repository.
*
* @return bool|string
*/
function find_repo_root() {
$possible_repo_roots = [
$_SERVER['PWD'],
getcwd(),
realpath(__DIR__ . '/../'),
realpath(__DIR__ . '/../../../'),
];
foreach ($possible_repo_roots as $possible_repo_root) {
if ($repo_root = find_directory_containing_files($possible_repo_root, ['vendor/bin/blt', 'vendor/autoload.php'])) {
return $repo_root;
}
}
}

/**
* Traverses file system upwards in search of a given file.
*
* Begins searching for $file in $working_directory and climbs up directories
* $max_height times, repeating search.
* @file This file is a simply shell wrapper for running BLT Robo commands.
*
* @param string $working_directory
* @param array $files
* @param int $max_height
*
* @return bool|string
* FALSE if file was not found. Otherwise, the directory path containing the
* file.
* Having a wrapper permits other non-shell files to directly require
* blt-robo.php.
*/
function find_directory_containing_files($working_directory, $files, $max_height = 10) {
// Find the root directory of the git repository containing BLT.
// We traverse the file tree upwards $max_height times until we find
// vendor/bin/blt.
$file_path = $working_directory;
for ($i = 0; $i <= $max_height; $i++) {
if (files_exist($file_path, $files)) {
return $file_path;
}
else {
$file_path = realpath($file_path . '/..');
}
}

return FALSE;
}

/**
* Determines if an array of files exist in a particular directory.
*
* @param string $dir
* @param array $files
*
* @return bool
*/
function files_exist($dir, $files) {
foreach ($files as $file) {
if (!file_exists($dir . '/' . $file)) {
return FALSE;
}
}
return TRUE;
}
// Shell wrapper for BLT robo app.
require_once __DIR__ . '/blt-robo.php';
11 changes: 0 additions & 11 deletions bin/blt-robo

This file was deleted.

81 changes: 81 additions & 0 deletions bin/blt-robo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

/**
* @file
*/

$repo_root = find_repo_root();
$autoload = require_once $repo_root . '/vendor/autoload.php';
if (!isset($autoload)) {
print "Unable to find autoloader for BLT\n";
exit(1);
}

require_once __DIR__ . '/blt-robo-run.php';

/**
* Finds the root directory for the repository.
*
* @return bool|string
*/
function find_repo_root() {
$possible_repo_roots = [
$_SERVER['PWD'],
getcwd(),
realpath(__DIR__ . '/../'),
realpath(__DIR__ . '/../../../'),
];
foreach ($possible_repo_roots as $possible_repo_root) {
if ($repo_root = find_directory_containing_files($possible_repo_root, ['vendor/bin/blt', 'vendor/autoload.php'])) {
return $repo_root;
}
}
}

/**
* Traverses file system upwards in search of a given file.
*
* Begins searching for $file in $working_directory and climbs up directories
* $max_height times, repeating search.
*
* @param string $working_directory
* @param array $files
* @param int $max_height
*
* @return bool|string
* FALSE if file was not found. Otherwise, the directory path containing the
* file.
*/
function find_directory_containing_files($working_directory, $files, $max_height = 10) {
// Find the root directory of the git repository containing BLT.
// We traverse the file tree upwards $max_height times until we find
// vendor/bin/blt.
$file_path = $working_directory;
for ($i = 0; $i <= $max_height; $i++) {
if (files_exist($file_path, $files)) {
return $file_path;
}
else {
$file_path = realpath($file_path . '/..');
}
}

return FALSE;
}

/**
* Determines if an array of files exist in a particular directory.
*
* @param string $dir
* @param array $files
*
* @return bool
*/
function files_exist($dir, $files) {
foreach ($files as $file) {
if (!file_exists($dir . '/' . $file)) {
return FALSE;
}
}
return TRUE;
}
5 changes: 3 additions & 2 deletions scripts/git-hooks/commit-msg
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#!/usr/bin/env php
<?php
echo "Executing .git/hooks/commit-msg...\n";
$repo_root = getcwd();

$original_argv = $_SERVER['argv'];
$commit_msg = rtrim(file_get_contents($original_argv[1]), "\n");

// Construct pseudo `blt commit-msg $commit_msg` call.
$_SERVER['argv'] = [
$repo_root . '/bin/blt-robo',
$repo_root . '/bin/blt',
'git:commit-msg',
$commit_msg,
];
$_SERVER['argc'] = count($_SERVER['argv']);

require __DIR__ . '/../../bin/blt';
require __DIR__ . '/../../bin/blt-robo.php';
1 change: 1 addition & 0 deletions scripts/git-hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ ROOT_DIR="$(pwd)/"
LIST=$( git diff --name-only --cached --diff-filter=ACM )
PHPCS_BIN=vendor/bin/phpcs

echo "Executing .git/hooks/pre-commit..."
${ROOT_DIR}/vendor/bin/blt git:pre-commit "$LIST"

# Return the status of the last run command.
Expand Down
2 changes: 1 addition & 1 deletion src/Robo/BltTasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ protected function invokeHook($hook) {
}
}
else {
$this->say("Skipped $hook target hook. No hook is defined.");
$this->logger->info("Skipped $hook target hook. No hook is defined.");

return 0;
}
Expand Down