From 40102252bffaf61b9d5418db29b5758337b8076b Mon Sep 17 00:00:00 2001 From: Nick Harper Date: Thu, 17 Jan 2013 11:28:13 -0800 Subject: [PATCH] Fix arc diff when run from a git submodule 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 | 14 +++++++++++++- src/workflow/ArcanistDiffWorkflow.php | 4 +++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/repository/api/ArcanistGitAPI.php b/src/repository/api/ArcanistGitAPI.php index fd1a23d3..23729890 100644 --- a/src/repository/api/ArcanistGitAPI.php +++ b/src/repository/api/ArcanistGitAPI.php @@ -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() { diff --git a/src/workflow/ArcanistDiffWorkflow.php b/src/workflow/ArcanistDiffWorkflow.php index 356c710b..2f3b08bb 100644 --- a/src/workflow/ArcanistDiffWorkflow.php +++ b/src/workflow/ArcanistDiffWorkflow.php @@ -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(); -- 2.43.0