From 6bd2b372f56d8fa2350950d06ea8eefb4d441ad8 Mon Sep 17 00:00:00 2001 From: vrana Date: Wed, 19 Sep 2012 15:59:39 -0700 Subject: [PATCH] Properly handle file moves in `arc patch` under SVN Summary: If the file has no changes (probably because it has been moved or copied) then we fail. Fixes T1708, fixes T1559. Test Plan: $ svn mv a b $ arc diff --only $ svn revert a b $ arc patch --diff # of created diff Reviewers: epriestley, btrahan Reviewed By: btrahan CC: aran, Korvin Maniphest Tasks: T1559, T1708 Differential Revision: https://secure.phabricator.com/D3526 --- src/parser/ArcanistBundle.php | 11 ++++++++- src/workflow/ArcanistPatchWorkflow.php | 31 ++++++++++++++++---------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/parser/ArcanistBundle.php b/src/parser/ArcanistBundle.php index 18222579..4812b0ab 100644 --- a/src/parser/ArcanistBundle.php +++ b/src/parser/ArcanistBundle.php @@ -212,6 +212,11 @@ final class ArcanistBundle { $changes = $this->getChanges(); foreach ($changes as $change) { + $hunk_changes = $this->buildHunkChanges($change->getHunks()); + if (!$hunk_changes) { + continue; + } + $old_path = $this->getOldPath($change); $cur_path = $this->getCurrentPath($change); @@ -245,7 +250,11 @@ final class ArcanistBundle { $result[] = '--- '.$old_path; $result[] = '+++ '.$cur_path; - $result[] = $this->buildHunkChanges($change->getHunks()); + $result[] = $hunk_changes; + } + + if (!$result) { + return ''; } $diff = implode("\n", $result)."\n"; diff --git a/src/workflow/ArcanistPatchWorkflow.php b/src/workflow/ArcanistPatchWorkflow.php index 22a9fa25..7caab84b 100644 --- a/src/workflow/ArcanistPatchWorkflow.php +++ b/src/workflow/ArcanistPatchWorkflow.php @@ -532,10 +532,8 @@ EOTEXT break; } if ($should_patch) { - if ($change->getHunks()) { - $cbundle = ArcanistBundle::newFromChanges(array($change)); - $patches[$change->getCurrentPath()] = $cbundle->toUnifiedDiff(); - } + $cbundle = ArcanistBundle::newFromChanges(array($change)); + $patches[$change->getCurrentPath()] = $cbundle->toUnifiedDiff(); $prop_old = $change->getOldProperties(); $prop_new = $change->getNewProperties(); $props = $prop_old + $prop_new; @@ -601,15 +599,24 @@ 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), - $err); + if ($patch) { + $tmp = new TempFile(); + Filesystem::writeFile($tmp, $patch); + passthru( + csprintf( + '(cd %s; patch -p0 < %s)', + $repository_api->getPath(), + $tmp), + $err); + } else { + passthru( + csprintf( + '(cd %s; touch %s)', + $repository_api->getPath(), + $path), + $err); + } if ($err) { $patch_err = max($patch_err, $err); }