]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Change patch generation for moving a file
authorNicholas Harper <nharper@fb.com>
Mon, 15 Aug 2011 19:25:05 +0000 (12:25 -0700)
committerNicholas Harper <nharper@fb.com>
Mon, 15 Aug 2011 22:36:45 +0000 (15:36 -0700)
Summary:
The unix utility `patch` will not move a file (unless it is in or out of
/dev/null). If a diff copies or moves a file and also makes changes to the file,
the generated patch needs to list the new filename as the path to both the
original and new files so the changes get written to the new file.

(When arc applies this patch, it copies or moves the original as needed before
running `patch`.)

(This only matters for svn repos, since arc uses git commands for git repos
instead of using `patch`.)

Test Plan:
Created an arc bundle of a diff that copied a file to a new location and made
changes in both locations, and then ran arc patch with this bundle (in an svn
repo) to see that it correctly patches.

Reviewed By: epriestley
Reviewers: epriestley, jungejason, tuomaspelkonen
CC: aran, epriestley, nh
Differential Revision: 813

src/parser/bundle/ArcanistBundle.php

index a591ca54dc9902427c3d572b1e304a887b785467..10320ec3263cdc443fc37f940fb2bf841b97dbf7 100644 (file)
@@ -150,6 +150,17 @@ class ArcanistBundle {
         $cur_path = '/dev/null';
       }
 
+      // When the diff is used by `patch`, `patch` ignores what is listed as the
+      // current path and just makes changes to the file at the old path (unless
+      // the current path is '/dev/null'.
+      // If the old path and the current path aren't the same (and neither is
+      // /dev/null), this indicates the file was moved or copied. By listing
+      // both paths as the new file, `patch` will apply the diff to the new
+      // file.
+      if ($cur_path !== '/dev/null' && $old_path !== '/dev/null') {
+        $old_path = $cur_path;
+      }
+
       $result[] = '--- '.$old_path;
       $result[] = '+++ '.$cur_path;