You are here

function drush_hacked_diff in Hacked! 8.2

Same name and namespace in other branches
  1. 5 hacked.drush.inc \drush_hacked_diff()
  2. 6.2 hacked.drush.inc \drush_hacked_diff()
  3. 6 hacked.drush.inc \drush_hacked_diff()
  4. 7.2 hacked.drush.inc \drush_hacked_diff()

Drush callback that shows the list of changes/unchanged files in a project.

You may specify the --include-unchanged option to show unchanged files too, otherwise just the changed and deleted files are shown.

Parameters

string $short_name: The project short name.

File

./hacked.drush.inc, line 371
Hacked drush command.

Code

function drush_hacked_diff($short_name) {
  $project = new hackedProject($short_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 = \Drupal::config('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 = drush_get_option('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);
    }
    drush_print($line);
  }
}