You are here

function drush_hacked_diff in Hacked! 7.2

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

Command callback for drush hacked_diff.

File

./hacked.drush.inc, line 395

Code

function drush_hacked_diff($short_name) {
  $project = hacked_project_load($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.
  if (variable_get('hacked_selected_file_hasher', HACKED_DEFAULT_FILE_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);
  }
}