/** * @param array $data * @param string $entityType */ public function storeData($data, $entityType) { parent::storeData($data, $entityType); $fileName = $this->_getEntityFilename($entityType); $git = new VersionControl_Git($this->_getStorageDirectory()); $fileName = substr($fileName, strlen($this->_getStorageDirectory())); try { $status = $git->getRevListFetcher(); $status->setSubCommand('status'); $status->addArgument('--porcelain'); $status_result = $status->execute(); foreach (explode("\n", $status_result) as $status_line) { $git_status = substr($status_line, 1, 1); $git_file = substr($status_line, 3); if (in_array($git_status, array('M', 'A'))) { $commit = $git->getCommand('commit'); $commit->setOption('message', 'current "' . $entityType . '" content'); $commit->addArgument($fileName); $commit->execute(); } } } catch (VersionControl_Git_Exception $e) { //if ( strpos($e->getMessage(), 'nothing to commit') === false ) //{ throw $e; //} } }
/** * @param bool $reset * @param null $repository * * @return null|VersionControl_Git * @throws BuildException */ protected function getGitClient($reset = false, $repository = null) { $this->gitClient = $reset === true ? null : $this->gitClient; $repository = null === $repository ? $this->getRepository() : $repository; if (null === $this->gitClient) { try { $this->gitClient = new VersionControl_Git($repository); } catch (VersionControl_Git_Exception $e) { // re-package throw new BuildException('You must specify readable directory as repository.', $e); } } $this->gitClient->setGitCommandPath($this->getGitPath()); return $this->gitClient; }
/** * Create a shallow clone with a history truncated to the specified number of revisions. * * @param VersionControl_Git $client * * @throws VersionControl_Git_Exception */ protected function doShallowClone(VersionControl_Git $client) { $command = $client->getCommand('clone')->setOption('depth', $this->getDepth())->setOption('q')->addArgument($this->getRepository())->addArgument($this->getTargetPath()); if (is_dir($this->getTargetPath()) && version_compare('1.6.1.4', $client->getGitVersion(), '>=')) { $isEmptyDir = true; $entries = scandir($this->getTargetPath()); foreach ($entries as $entry) { if ('.' !== $entry && '..' !== $entry) { $isEmptyDir = false; break; } } if ($isEmptyDir) { @rmdir($this->getTargetPath()); } } $command->execute(); }
private function commitChanges($path = null) { $git = new VersionControl_Git($this->repoBase); $command = $git->getCommand("add"); $command->addArgument("."); try { $cmd = $command->createCommandString(); $this->logDebug("Git command " . $cmd); $res = $command->execute(); } catch (Exception $e) { $this->logDebug("Error " . $e->getMessage()); } $this->logDebug("GIT RESULT ADD : " . $res); $command = $git->getCommand("commit"); $command->setOption("a", true); $userId = "no user"; $mail = "*****@*****.**"; if (AuthService::getLoggedUser() != null) { $userId = AuthService::getLoggedUser()->getId(); $mail = AuthService::getLoggedUser()->personalRole->filterParameterValue("core.conf", "email", AJXP_REPO_SCOPE_ALL, "*****@*****.**"); } $command->setOption("m", $userId); $command->setOption("author", "{$userId} <{$mail}>"); //$command->addArgument($path); try { $cmd = $command->createCommandString(); $this->logDebug("Git command " . $cmd); $res = $command->execute(); } catch (Exception $e) { $this->logDebug("Error " . $e->getMessage()); } $this->logDebug("GIT RESULT COMMIT : " . $res); }
public function testSetGitCommandPath() { $instance = new VersionControl_Git('./fixtures/001_VersionControl_Git'); $this->assertEquals($instance->getGitCommandPath(), @System::which('git')); $instance->setGitCommandPath('/usr/local/bin/git'); $this->assertEquals($instance->getGitCommandPath(), '/usr/local/bin/git'); }
<?php require_once '/php/VersionControl/Git.php'; // Specify a directory $git = new VersionControl_Git('../../../../public_html/sitionuevo/test'); // create new repository $git->createClone('git@github.com:aopazo/web.git'); $commits = $git->getCommits(); // exec("git pull git@github.com:aopazo/web.git master", $output, $return_var); // exec("ls", $output); ?> <html> <body> Commits: <?php echo $commits; ?> <br /> Script ejecutado. </body> </html>
private function commitChanges($path = null) { $git = new VersionControl_Git($this->repoBase); $command = $git->getCommand("add"); $command->addArgument("."); try { $cmd = $command->createCommandString(); AJXP_Logger::debug("Git command " . $cmd); $res = $command->execute(); } catch (Exception $e) { AJXP_Logger::debug("Error " . $e->getMessage()); } AJXP_Logger::debug("GIT RESULT ADD : " . $res); $command = $git->getCommand("commit"); $command->setOption("a", true); $userId = "no user"; if (AuthService::getLoggedUser() != null) { $userId = AuthService::getLoggedUser()->getId(); } $command->setOption("m", $userId); //$command->addArgument($path); try { $cmd = $command->createCommandString(); AJXP_Logger::debug("Git command " . $cmd); $res = $command->execute(); } catch (Exception $e) { AJXP_Logger::debug("Error " . $e->getMessage()); } AJXP_Logger::debug("GIT RESULT COMMIT : " . $res); }
protected function importFromGit($gitUrl, $gitCommit) { $filesystem = new sfFilesystem(); require_once 'VersionControl/Git.php'; $dir = sfConfig::get('sf_cache_dir') . '/git-' . md5($gitUrl . $gitCommit); $filesystem->mkdirs($dir); $git = new VersionControl_Git(sfConfig::get('sf_cache_dir')); $git->createClone($gitUrl, false, $dir); $filesystem->chmod($dir, 0777); $git->checkout($gitCommit); return $dir; }