From a4f484f2f17b8bb8ac3fa724b1f4c7ea9b62061d Mon Sep 17 00:00:00 2001 From: Steven Jones Date: Wed, 29 Jun 2011 15:29:36 +0100 Subject: [PATCH 1/2] Add patch from issue 745224#102 --- drush_make.project.inc | 31 ++++++++++++++++++++++++++++--- 1 files changed, 28 insertions(+), 3 deletions(-) diff --git a/drush_make.project.inc b/drush_make.project.inc index 3359046..4049b84 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_cd_and_exec($this->project_directory, 'git apply --check %s %s', $patch_level, $filename); + if ($checked) { + // Apply the first successful style. + $patched = drush_shell_cd_and_exec($this->project_directory, 'git apply %s %s', $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 { @@ -324,4 +350,3 @@ class DrushMakeProject_Translation extends DrushMakeProject { } } } - -- 1.7.4.1 From ec931890a29d56291f88321fdf1c1845051f896b Mon Sep 17 00:00:00 2001 From: Steven Jones Date: Wed, 29 Jun 2011 15:33:04 +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 4049b84..c2eb1c0 100644 --- a/drush_make.project.inc +++ b/drush_make.project.inc @@ -73,6 +73,7 @@ class DrushMakeProject { // Download the patch. if ($filename = _drush_make_download_file($info)) { $patched = FALSE; + $output = ''; // Test each patch style; -p1 is the default with git. See // http://drupal.org/node/1054616 $patch_levels = array('-p1', '-p0'); @@ -85,8 +86,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", $this->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