]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Fix 'arc patch' when adding files in new directories
authorepriestley <epriestley@javelinjs.com>
Tue, 8 Mar 2011 04:21:16 +0000 (20:21 -0800)
committerepriestley <epriestley@javelinjs.com>
Tue, 8 Mar 2011 06:09:02 +0000 (22:09 -0800)
Summary:
If you apply an arcbundle to a subversion working copy which adds
files in new subdirectories, we fail to create and add the parent directories
so the whole operation fails. Make sure we create and add any missing parent
directories before apply patches.

Test Plan:
Applied Facebook diff #542056 to www@rE349795 cleanly, while it
failed previously.

Reviewed By: aran
Reviewers: aran
CC: aran
Differential Revision: 62

src/workflow/patch/ArcanistPatchWorkflow.php

index 241684d56970d16afb89f16faa47436eac91750a..71ec07e75e1a4d250bf79202281ccbfe166baf3b 100644 (file)
@@ -237,6 +237,21 @@ EOTEXT
         }
       }
 
+      // Before we start doing anything, create all the directories we're going
+      // to add files to if they don't already exist.
+      foreach ($copies as $copy) {
+        list($src, $dst) = $copy;
+        $this->createParentDirectoryOf($dst);
+      }
+
+      foreach ($patches as $path => $patch) {
+        $this->createParentDirectoryOf($path);
+      }
+
+      foreach ($adds as $add) {
+        $this->createParentDirectoryOf($add);
+      }
+
       foreach ($copies as $copy) {
         list($src, $dst) = $copy;
         passthru(
@@ -336,4 +351,28 @@ EOTEXT
     // TODO: Pull open diffs from 'arc list'?
     return array('ARGUMENT');
   }
+
+  /**
+   * Create parent directories one at a time, since we need to "svn add" each
+   * one. (Technically we could "svn add" just the topmost new directory.)
+   */
+  private function createParentDirectoryOf($path) {
+    $repository_api = $this->getRepositoryAPI();
+    $dir = dirname($path);
+    if (Filesystem::pathExists($dir)) {
+      return;
+    } else {
+      // Make sure the parent directory exists before we make this one.
+      $this->createParentDirectoryOf($dir);
+      execx(
+        '(cd %s && mkdir %s)',
+        $repository_api->getPath(),
+        $dir);
+      passthru(
+        csprintf(
+          '(cd %s && svn add %s)',
+          $repository_api->getPath(),
+          $dir));
+    }
+  }
 }