]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Properly handle file moves in `arc patch` under SVN
authorvrana <jakubv@fb.com>
Wed, 19 Sep 2012 22:59:39 +0000 (15:59 -0700)
committervrana <jakubv@fb.com>
Fri, 21 Sep 2012 18:22:05 +0000 (11:22 -0700)
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
src/workflow/ArcanistPatchWorkflow.php

index 18222579653a3975a072c6a95a6b56e02ab14fee..4812b0ab36f216b3afac4009491fa613cd33b9a8 100644 (file)
@@ -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";
index 22a9fa2526479ba16b57a896e7c33a31bbd309bb..7caab84b54ed76be917f66fe9b35f35a42f28473 100644 (file)
@@ -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);
         }