Skip to content

Commit

Permalink
GitRepository: added getCommitDate() & getCommitAuthor()
Browse files Browse the repository at this point in the history
  • Loading branch information
sudo-plz authored Jun 30, 2020
1 parent d38e58a commit ed44221
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/GitRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,44 @@ public function getCommitMessage($commit, $oneline = FALSE)
return implode(PHP_EOL, $message);
}

/**
* Returns commit date from specific commit
* `git log -1 --date=iso-strict`
* @param string commit ID (if empty last commit)
* @param string date format (eg. 'iso-strict' or 'format:'%Y-%m-%d %H:%M:%S'')
* @return \DateTime|NULL
* @throws GitException
*/
public function getCommitDate($commit = '', $dateFormat = 'iso-strict')
{
$this->begin();
$lastLine = exec('git log -1 ' . $commit . ' --date=' . $dateFormat);
$this->end();

try {
return new \DateTime($lastLine);
} catch (\Exception $e) {
return null;
}
}


/**
* Returns commit author from specific commit
* `git log -1 --format='%ae'`
* @param string commit ID (if empty last commit)
* @return string|NULL
* @throws GitException
*/
public function getCommitAuthor($commit = '')
{
$this->begin();
$lastLine = exec('git log -1 ' . $commit . ' --format="%ae"');
$this->end();

return $lastLine;
}


/**
* Returns array of commit metadata from specific commit
Expand Down

0 comments on commit ed44221

Please sign in to comment.