/** * Get Git commit hash of project * * @param string $hash Specified hash * * @return string Git commit hash * * @throws \InvalidArgumentException When bad hash specified, or can't get commit hash */ protected function getCommitHash($hash = null) { if (!$hash) { $gClient = new GitClient(getcwd()); return $gClient->getHashOfLatestCommit(); } if (strlen($hash) != 40) { throw new \InvalidArgumentException(sprintf("Invalid git commit hash %s specified", $hash)); } return urlencode($hash); }
public function testGetHashOfLastCommit() { $gitClient = new GitClient(getcwd()); $hash = $gitClient->getHashOfLatestCommit(); $this->assertEquals(40, strlen($hash)); }