From 40bb62b2be2e347c43e74ef84243be19f1cc5e40 Mon Sep 17 00:00:00 2001 From: Steven Jones Date: Mon, 6 Jun 2011 09:47:17 +0100 Subject: [PATCH 1/2] Issue #745224 by medlefsen, glennpratt, jhedstrom, q0rban, rfay, Steven Jones: Fixed Apply patches from git diff and git format-patch. --- drush_make.project.inc | 32 +++++++++++++++++++++++++++++--- 1 files changed, 29 insertions(+), 3 deletions(-) diff --git a/drush_make.project.inc b/drush_make.project.inc index 8f797cb..8c5bdf8 100644 --- a/drush_make.project.inc +++ b/drush_make.project.inc @@ -105,14 +105,41 @@ class DrushMakeProject { } // Download the patch. if ($filename = _drush_make_download_file($info)) { - $patched = drush_shell_exec("patch -p0 -d %s < %s", $project_directory, $filename); + //$patched = drush_shell_exec("patch -p0 -d %s < %s", $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', $project_directory, $patch_level, $filename); + if ($checked) { + // Apply the first successful style. + $patched = drush_shell_exec('cd %s && git apply %s %s', $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 { @@ -356,4 +383,3 @@ class DrushMakeProject_Translation extends DrushMakeProject { } } } - -- 1.7.4.1 From 5feff31337d9aa689bb978f49fa5998fabbb4c7f Mon Sep 17 00:00:00 2001 From: Steven Jones Date: Wed, 29 Jun 2011 15:03:07 +0100 Subject: [PATCH 2/2] Fallback to patch -p0 if git apply fails us. --- drush_make.project.inc | 13 ++++++++++++- 1 files changed, 12 insertions(+), 1 deletions(-) diff --git a/drush_make.project.inc b/drush_make.project.inc index 8c5bdf8..6a99986 100644 --- a/drush_make.project.inc +++ b/drush_make.project.inc @@ -107,6 +107,7 @@ class DrushMakeProject { if ($filename = _drush_make_download_file($info)) { //$patched = drush_shell_exec("patch -p0 -d %s < %s", $project_directory, $filename); $patched = FALSE; + $output = ''; // Test each patch style; -p1 is the default with git. See // http://drupal.org/node/1054616 $patch_levels = array('-p1', '-p0'); @@ -119,8 +120,18 @@ class DrushMakeProject { } } - // Log any command output, visible only in --verbose or --debug mode. + // In some rare cases, git will fail to apply a -p0 patch with new files + // fallback to using the 'patch -p0' command if we can detect that case. if ($output = drush_shell_exec_output()) { + $git_output = implode("\n", $output); + if (!$patched && (strpos($git_output, 'fatal: git apply: bad git-diff - inconsistent new filename ') !== FALSE)) { + $patched = drush_shell_exec("patch -p0 -d %s < %s", $project_directory, $filename); + $output = drush_shell_exec_output(); + } + } + + if (!empty($output)) { + // Log any command output, visible only in --verbose or --debug mode. drush_log(implode("\n", $output)); } -- 1.7.4.1