/** * repoPath: data repo path since using git-data-repo * e.g. /var/cache/ffamfe_tcm * authFn: e.g. __DIR__."/../auth.json", false for no credentials, e.g. read-only usage of public repo * remote, e.g. https://bitbucket.org/shadiakiki1986/ffa-bdlreports-maps * loglevel=\Monolog\Logger::WARNING; // isset($argc)?\Monolog\Logger::DEBUG:\Monolog\Logger::WARNING; * gitconfig: e.g. array('user.email'=>'*****@*****.**','user.name'=>'my name') * * @SuppressWarnings(PHPMD.StaticAccess) */ public static function initGdrPersistentFromAuthJson($repoPath, $authFn, $remoteUrl, $loglevel = \Monolog\Logger::WARNING, $gitconfig = array()) { // copied from accounting-bdlreports-mapeditor/action.php // check can put files here if (!is_writable($repoPath)) { throw new \Exception("Cache folder '" . $repoPath . "' is not writable. You may need `[sudo] chown www-data:www-data -R " . $repoPath . "`"); } // get remote credentials $remote = null; if ($authFn) { if (!file_exists($authFn)) { throw new \Exception("File not found '" . $authFn . "'"); } $remote = json_decode(file_get_contents($authFn), true); $remote = $remote["http-basic"]["bitbucket.org"]; $remote = GitDataRepo::injectRemoteCredentials($remoteUrl, $remote["username"], $remote["password"]); } else { $remote = $remoteUrl; } # copied from https://github.com/coyl/git/blob/master/src/Coyl/Git/GitRepo.php#L43 $isgit = is_dir($repoPath) && file_exists($repoPath . "/.git") && is_dir($repoPath . "/.git"); if ($isgit) { $gitRepo = new \Coyl\Git\GitRepo($repoPath, false, false); return new \GitDataRepo\GitDataRepo($gitRepo, $remote, $loglevel); } # case of new git repo $gitRepo = \Coyl\Git\GitRepo::create($repoPath, $remote); # run some git config if needed foreach ($gitconfig as $k => $v) { $cmd = "config " . $k . " '" . $v . "'"; $gitRepo->run($cmd); } return new \GitDataRepo\GitDataRepo($gitRepo, $remote, $loglevel); }
public function testDate() { $source = "https://github.com/shadiakiki1986/ffa-gdr-public"; $path = tempnam("/tmp", "test"); unlink($path); mkdir($path); $gdr = GitDataRepo::initGdrPersistentFromAuthJson($path, false, $source); $dd = $gdr->date(); $this->assertInstanceOf('DateTime', $dd); }