diff --git a/drush_make.project.inc b/drush_make.project.inc index 3359046..a5435d7 100644 --- a/drush_make.project.inc +++ b/drush_make.project.inc @@ -66,15 +66,32 @@ class DrushMakeProject { $patches_txt = ''; $ignore_checksums = drush_get_option('ignore-checksums'); + + // Change to build directory. + $cwd = getcwd(); + chdir($this->project_directory); + foreach ($this->patch as $info) { if (!is_array($info)) { $info = array('url' => $info); } // 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(1, 0); + foreach ($patch_levels as $patch_level) { + $checked = drush_shell_exec('git apply --check -p%s --directory %s %s', $patch_level, $this->project_directory, $filename); + if ($checked) { + // Apply the first successful style. + $patched = drush_shell_exec('git apply -p%s --directory %s %s', $patch_level, $this->project_directory, $filename); + break; + } + } + if ($patched) { if (!$ignore_checksums && !_drush_make_verify_checksums($info, $filename)) { + chdir($cwd); return FALSE; } $patches_txt .= '- ' . $info['url'] . "\n"; @@ -84,6 +101,7 @@ class DrushMakeProject { } else { drush_make_error('Unable to download ' . $info['url'] . '.'); + chdir($cwd); return FALSE; } } @@ -94,6 +112,7 @@ class DrushMakeProject { file_put_contents($this->project_directory . '/PATCHES.txt', $patches_txt); drush_log('Generated PATCHES.txt file for ' . $this->name, 'ok'); } + chdir($cwd); return TRUE; }