From 50f42aad8d9eac96eff0575a4da373752d510161 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 13 Jan 2011 13:21:33 -0800 Subject: [PATCH] Provide a better error message for 'arc patch' when patches fail. Summary: Be more clear about what happened. Test Plan: ran 'arc patch' on good/bad patches Differential Revision: 201085 Reviewed By: adonohue Reviewers: adonohue CC: adonohue Revert Plan: OK --- src/workflow/diff/ArcanistDiffWorkflow.php | 2 +- src/workflow/patch/ArcanistPatchWorkflow.php | 30 ++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/workflow/diff/ArcanistDiffWorkflow.php b/src/workflow/diff/ArcanistDiffWorkflow.php index 6e928ea4..7135c255 100644 --- a/src/workflow/diff/ArcanistDiffWorkflow.php +++ b/src/workflow/diff/ArcanistDiffWorkflow.php @@ -20,7 +20,7 @@ class ArcanistDiffWorkflow extends ArcanistBaseWorkflow { private $hasWarnedExternals = false; private $unresolvedLint; - private $unresolvedUnit; + private $unresolvedTests; public function getCommandHelp() { return phutil_console_format(<<getRepositoryAPI(); if ($repository_api instanceof ArcanistSubversionAPI) { + $patch_err = 0; + $copies = array(); $deletes = array(); $patches = array(); @@ -248,11 +250,16 @@ EOTEXT foreach ($patches as $path => $patch) { $tmp = new TempFile(); Filesystem::writeFile($tmp, $patch); + $err = null; passthru( csprintf( '(cd %s; patch -p0 < %s)', $repository_api->getPath(), - $tmp)); + $tmp), + $err); + if ($err) { + $patch_err = max($patch_err, $err); + } } foreach ($adds as $add) { @@ -286,13 +293,32 @@ EOTEXT } } - echo "Applied patch.\n"; + if ($patch_err == 0) { + echo phutil_console_format( + "** OKAY ** Successfully applied patch to the ". + "working copy.\n"); + } else { + echo phutil_console_format( + "\n\n** WARNING ** Some hunks could not be applied ". + "cleanly by the unix 'patch' utility. Your working copy may be ". + "different from the revision's base, or you may be in the wrong ". + "subdirectory. You can export the raw patch file using ". + "'arc export --unified', and then try to apply it by fiddling with ". + "options to 'patch' (particularly, -p), or manually. The output ". + "above, from 'patch', may be helpful in figuring out what went ". + "wrong.\n"); + } + + return $patch_err; } else { $future = new ExecFuture( '(cd %s; git apply --index)', $repository_api->getPath()); $future->write($bundle->toGitPatch()); $future->resolvex(); + + echo phutil_console_format( + "** OKAY ** Successfully applied patch.\n"); } return 0;