]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Fix arc diff when run from a git submodule
authorNick Harper <nharper@fb.com>
Thu, 17 Jan 2013 19:28:13 +0000 (11:28 -0800)
committerNick Harper <nharper@fb.com>
Thu, 17 Jan 2013 19:28:13 +0000 (11:28 -0800)
Summary:
A git submodule looks a lot like a normal git repo, but the .git
directory is replaced with a file that git reads to find the real
location of the git directory. When arcanist tries to write a file into
a directory inside of there, it was failing silently, and then crashing
silently when it couldn't read results back out. Instead of assuming the
git directory is a directory named .git at the toplevel of the tree, we
use the appropriate git command to get the correct git directory.

Test Plan: submit a diff from a submodule

Reviewers: epriestley, vrana

Reviewed By: epriestley

CC: aran, Korvin
Differential Revision: https://secure.phabricator.com/D4482

src/repository/api/ArcanistGitAPI.php
src/workflow/ArcanistDiffWorkflow.php

index fd1a23d339fa9b19286b7dd928128e569fb45bf9..23729890b9b3a75b24142137fb0c38b338bfffad 100644 (file)
@@ -35,7 +35,19 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI {
   }
 
   public function getMetadataPath() {
-    return $this->getPath('.git');
+    static $path = null;
+    if ($path === null) {
+      list($stdout) = $this->execxLocal('rev-parse --git-dir');
+      $path = rtrim($stdout, "\n");
+      // the output of git rev-parse --git-dir is an absolute path, unless
+      // the cwd is the root of the repository, in which case it uses the
+      // relative path of .git. If we get this relative path, turn it into
+      // an absolute path.
+      if ($path === '.git') {
+        $path = $this->getPath('.git');
+      }
+    }
+    return $path;
   }
 
   public function getHasCommits() {
index 356c710b5798778e1d88094de75fb3fc5989e044..2f3b08bbce93f23560673d1209deada7a24f92b5 100644 (file)
@@ -445,7 +445,9 @@ EOTEXT
       list($err) = $lint_unit->resolve();
       $data = $this->readScratchJSONFile('diff-result.json');
       if ($err || !$data) {
-        return 1;
+        throw new Exception(
+          'Unable to read results from background linting and unit testing. '.
+          'You can try running arc diff again with --background 0');
       }
     } else {
       $server = $this->console->getServer();