From 62846b79d38439cbc02169b6623e9c12f1323047 Mon Sep 17 00:00:00 2001 From: James Sansbury Date: Thu, 12 May 2011 10:37:29 -0400 Subject: [PATCH] #745224 by medlefsen, glennpratt, jhedstrom, q0rban, rfay: Apply patches from git-diff and git-format-patch. --- drush_make.project.inc | 30 ++++++++++++++++++++++++++++-- 1 files changed, 28 insertions(+), 2 deletions(-) diff --git a/drush_make.project.inc b/drush_make.project.inc index 3359046..67d2afa 100644 --- a/drush_make.project.inc +++ b/drush_make.project.inc @@ -72,14 +72,40 @@ class DrushMakeProject { } // Download the patch. if ($filename = _drush_make_download_file($info)) { - $patched = drush_shell_exec("patch -p0 -d %s < %s", $this->project_directory, $filename); + $patched = FALSE; + // Test each patch style; -p1 is the default with git. See + // http://drupal.org/node/1054616 + $patch_levels = array('-p1', '-p0'); + foreach ($patch_levels as $patch_level) { + $checked = drush_shell_exec('cd %s && git apply --check %s %s', $this->project_directory, $patch_level, $filename); + if ($checked) { + // Apply the first successful style. + $patched = drush_shell_exec('cd %s && git apply %s %s', $this->project_directory, $patch_level, $filename); + break; + } + } + + // Log any command output, visible only in --verbose or --debug mode. + if ($output = drush_shell_exec_output()) { + drush_log(implode("\n", $output)); + } + + // Set up string placeholders to pass to dt(). + $dt_args = array( + '@name' => $this->name, + '@filename' => basename($filename), + ); + if ($patched) { if (!$ignore_checksums && !_drush_make_verify_checksums($info, $filename)) { return FALSE; } $patches_txt .= '- ' . $info['url'] . "\n"; + drush_log(dt('@name patched with @filename.', $dt_args), 'ok'); + } + else { + drush_log(dt("Unable to patch @name with @filename.", $dt_args), 'error'); } - drush_log($this->name . ' patched with ' . basename($filename) . '.', $patched ? 'ok' : 'error'); drush_op('unlink', $filename); } else { -- 1.7.2.2