]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Improve getting Git author
authorvrana <jakubv@fb.com>
Thu, 29 Nov 2012 23:35:57 +0000 (15:35 -0800)
committervrana <jakubv@fb.com>
Fri, 30 Nov 2012 19:09:31 +0000 (11:09 -0800)
Summary:
It has one more than source, see http://www.kernel.org/pub/software/scm/git/docs/git-commit-tree.html#_commit_information.
Also 'user.name' may not be set at all.
Also `git config` returns non-zero for non-existing value.

Test Plan:
  var_dump($api->getAuthor());

Reviewers: epriestley

Reviewed By: epriestley

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

src/repository/api/ArcanistGitAPI.php

index 8e3b8065dae713d02b78e67c09fa906589e64613..1cfd5d267f3d538d05f2c290ccdcc52e96ec101d 100644 (file)
@@ -473,15 +473,16 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI {
   }
 
   public function getGitConfig($key, $default = null) {
-    list($stdout) = $this->execxLocal('config %s', $key);
-    if ($stdout == '') {
+    list($err, $stdout) = $this->execManualLocal('config %s', $key);
+    if ($err) {
       return $default;
     }
     return rtrim($stdout);
   }
 
   public function getAuthor() {
-    return $this->getGitConfig('user.name');
+    list($stdout) = $this->execxLocal('var GIT_AUTHOR_IDENT');
+    return preg_replace('/\s+<.*/', '', rtrim($stdout, "\n"));
   }
 
   public function addToCommit(array $paths) {