diff --git a/drush_make.project.inc b/drush_make.project.inc index 3359046..a86203b 100644 --- a/drush_make.project.inc +++ b/drush_make.project.inc @@ -72,14 +72,47 @@ 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; + $output = ''; + // 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_WORK_TREE=. 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_WORK_TREE=. git apply --verbose %s %s', $patch_level, $filename); + break; + } + } + + // In some rare cases, git will fail to apply a patch, fallback to using + // the 'patch -p0' command. + if (!$patched) { + $patched = drush_shell_exec("patch -p0 -d %s < %s", $this->project_directory, $filename); + } + + if ($output = drush_shell_exec_output()) { + // Log any command output, visible only in --verbose or --debug mode. + 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 +357,3 @@ class DrushMakeProject_Translation extends DrushMakeProject { } } } - diff --git a/tests/patches.make b/tests/patches.make index 5571d0f..df9baad 100644 --- a/tests/patches.make +++ b/tests/patches.make @@ -4,4 +4,4 @@ api = 2 ; Test that patches work projects[token][version] = 1.13 projects[token][patch][] = http://drupal.org/files/issues/new_role_email_action5.patch -projects[token][patch][] = http://drupal.org/files/issues/token_module_array_resolution_587148_01.patch \ No newline at end of file +projects[token][patch][] = http://drupal.org/files/issues/587148-token-check-duplicate-tokens.patch diff --git a/tests/tests.info b/tests/tests.info index d6d5225..7509d8e 100644 --- a/tests/tests.info +++ b/tests/tests.info @@ -15,12 +15,12 @@ tests[no-patch-txt][name] = "Test --no-patch-txt option" tests[no-patch-txt][makefile] = "tests/patches.make" - tests[no-patch-txt][messages][] = "Build hash: 24f14f6e28498678cebcab2cff3e1030" + tests[no-patch-txt][messages][] = "Build hash: e2d38e343c7e95b994443c34ec665a23" tests[no-patch-txt][options][no-patch-txt] = TRUE tests[patch][name] = "Test patching and writing of PATCHES.txt file" tests[patch][makefile] = "tests/patches.make" - tests[patch][messages][] = "Build hash: 173ae5e2120463e31ff2e2a9cc02491b" + tests[patch][messages][] = "Build hash: c17e8b59055db741778f9048bf289332" tests[recursion][name] = "Recursion" tests[recursion][makefile] = "tests/recursion.make"