public function HackedCommands::diff in Hacked! 8.2
Output a unified diff of the project specified.
You may specify the --include-unchanged option to show unchanged files too, otherwise just the changed and deleted files are shown.
@option diff-options Command line options to pass through to the diff command.
@command hacked:diff @aliases hacked-diff
@validate-module-enabled hacked
Parameters
string $machine_name: The machine name of the project to report on.
array $options: An associative array of options whose values come from cli, aliases, config, etc.
File
- src/
Commands/ HackedCommands.php, line 271
Class
- HackedCommands
- A Drush commandfile for Hacked! module.
Namespace
Drupal\hacked\CommandsCode
public function diff($machine_name, array $options = [
'diff-options' => NULL,
]) {
$project = new hackedProject($machine_name);
$local_location = $project
->file_get_location('local', '');
$clean_location = $project
->file_get_location('remote', '');
// If the hasher is our ignore line endings one, then ignore line endings.
$hasher = $this->configFactory
->get('hacked.settings')
->get('selected_file_hasher');
$hasher = is_null($hasher) ? HACKED_DEFAULT_FILE_HASHER : $hasher;
if ($hasher == 'hacked_ignore_line_endings') {
$default_options = '-uprb';
}
else {
$default_options = '-upr';
}
$diff_options = isset($options['diff-options']) ? $options['diff-options'] : $default_options;
drush_shell_exec("diff {$diff_options} {$clean_location} {$local_location}");
$lines = drush_shell_exec_output();
$local_location_trim = dirname($local_location . '/dummy.file') . '/';
$clean_location_trim = dirname($clean_location . '/dummy.file') . '/';
foreach ($lines as $line) {
if (strpos($line, '+++') === 0) {
$line = str_replace($local_location_trim, '', $line);
}
if (strpos($line, '---') === 0) {
$line = str_replace($clean_location_trim, '', $line);
}
if (strpos($line, 'diff -upr') === 0) {
$line = str_replace($clean_location_trim, 'a/', $line);
$line = str_replace($local_location_trim, 'b/', $line);
}
$this
->output()
->writeln($line);
}
}