From 32dd82611ae9788566972862c64ba07ef3fff2e8 Mon Sep 17 00:00:00 2001 From: James Sansbury Date: Tue, 10 May 2011 23:16:10 -0400 Subject: [PATCH] #745224 by medlefsen, glennpratt, jhedstrom, q0rban, rfay: Apply patches from git-diff and git-format-patch. --- README.txt | 23 +++++++++++++++-- drush_make.project.inc | 64 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 82 insertions(+), 5 deletions(-) diff --git a/README.txt b/README.txt index dc3a676..875cbdc 100644 --- a/README.txt +++ b/README.txt @@ -158,13 +158,30 @@ Do not use both types of declarations for a single project in your makefile. - `patch` One or more patches to apply to this project. An array of URLs from which - each patch should be retrieved. + each patch should be retrieved. By default, this assumes patch was created + with git-diff and the -p1 option (see http://drupal.org/patch/create and + http://groups.drupal.org/node/140204). You may specify different options + using the options array on the patch. These options can either be a single + string, or an array of options. + + ; shorthand syntax if no md5 checksum is specified + projects[adminrole][patch][] = "http://drupal.org/files/issues/adminrole_exceptions.patch" projects[calendar][patch][rfc-fixes][url] = "http://drupal.org/files/issues/cal-760316-rfc-fixes-2.diff" projects[calendar][patch][rfc-fixes][md5] = "e4876228f449cb0c37ffa0f2142" - ; shorthand syntax if no md5 checksum is specified - projects[adminrole][patch][] = "http://drupal.org/files/issues/adminrole_exceptions.patch" + ; -p1 will be used by default, but this diff was created using -p0 + projects[calendar][patch][rfc-fixes][options] = "-p0 -v" + ; Alternately, you can specify an array of patch command options. + projects[calendar][patch][rfc-fixes][options][] = "-p0" + projects[calendar][patch][rfc-fixes][options][] = "-v" + + You can also specify a different patch type. Options are git-diff (default), + diff, and git-format-patch. Please note, using git-format-patch requires that + the download type for the project be git, and for the drush make command to + be executed with --working-copy. + + projects[calendar][patch][rfc-fixes][type] = "diff" - `subdir` diff --git a/drush_make.project.inc b/drush_make.project.inc index 3359046..ee07ffb 100644 --- a/drush_make.project.inc +++ b/drush_make.project.inc @@ -70,16 +70,76 @@ class DrushMakeProject { if (!is_array($info)) { $info = array('url' => $info); } + // Set up patch command options, if they exist. + if (isset($info['options'])) { + $options = is_array($info['options']) ? implode(' ', $info['options']) : $info['options']; + } + // Assume git-diff created the patch. Other options are diff and git-format-patch. + $type = isset($info['type']) ? $info['type'] : 'git-diff'; + // Download the patch. if ($filename = _drush_make_download_file($info)) { - $patched = drush_shell_exec("patch -p0 -d %s < %s", $this->project_directory, $filename); + // Set up string placeholders to pass to dt(). + $dt_args = array( + '@name' => $this->name, + '@filename' => basename($filename), + ); + + switch ($type) { + case 'git-diff': + $options = isset($options) ? $options : '-v --check --apply'; + $args = array( + "cd %s; git apply %s %s", + $this->project_directory, + $options, + $filename, + ); + break; + + case 'diff': + $options = isset($options) ? $options : '-p1'; + $args = array( + "patch %s -d %s < %s", + $options, + $this->project_directory, + $filename, + ); + break; + + case 'git-format-patch': + if ($this->download['type'] != 'git') { + drush_log(dt('The patch from @filename expects @name to be downloaded with git.', $dt_args), 'warning'); + } + if (!drush_get_option('working-copy')) { + drush_log(dt("Using a patch type of git-format-patch requires the make command be executed with '--workin + } + $options = isset($options) ? $options : '-p1'; + $args = array( + "cd %s; git am %s %s", + $this->project_directory, + $options, + $filename, + ); + break; + } + + $patched = call_user_func_array('drush_shell_exec', $args); + + // Log any command output, visible only in --verbose or --debug mode. + if ($output = drush_shell_exec_output()) { + drush_log(implode("\n", $output)); + } + 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.3.4