From 4c05dc3cd61dd99b09ec3328ae7e2ee52d2f212b Mon Sep 17 00:00:00 2001 From: Nicholas Harper Date: Mon, 15 Aug 2011 12:25:05 -0700 Subject: [PATCH] Change patch generation for moving a file 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 | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/parser/bundle/ArcanistBundle.php b/src/parser/bundle/ArcanistBundle.php index a591ca54..10320ec3 100644 --- a/src/parser/bundle/ArcanistBundle.php +++ b/src/parser/bundle/ArcanistBundle.php @@ -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;