You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

66 lines
1.8 KiB

<?php
/**
* autodoc
*
* Permet l'extraction des informations SVN d'un répertoire
*/
namespace autodoc\Plugin\Core\Compiler\Pass\VcsInformations;
/**
* Extraction d'informations d'un dossier utilisant un Vcs
**/
class Git extends VcsInformationsAbstract
{
/**
* Données XML de l'extraction
* @var SimpleXMLElement|null
**/
private $xml;
/**
* {@inheritDoc}
**/
public function extractWithDirectory($dir) {
$this->clear();
// obtenir les infos SVN
exec("cd $dir ; checkout.php --read . 2> /dev/null", $output);
// la sortie doit avoir plus de 3 lignes, sinon c'est une erreur !
if ($output) {
$res = trim($output[0]);
$res = explode(' ', $res);
$infos = [];
$infos['revision'] = substr($res[2], 2); // -r{revision}
$infos['branche'] = substr($res[3], 2); // -b{branche}
$infos['url'] = $url = $res[4];
if (false !== strpos($url, '@')) {
// git@git.spip.net:path ...
list($root, $path) = explode(':', $url, 2);
} else {
// https://git.spip.net/path ...
list($protocol, $path) = explode('://', $url, 2);
list($root, $path) = explode('/', $path, 2);
$root = $protocol . '://' . $root;
}
$infos['root'] = $root;
$infos['path'] = $path;
# https://git.spip.net/SPIP/spip.git
$this->setUrlPath( $infos['url'] );
# git.spip.net
$this->setUrlRoot( $infos['root'] );
# SPIP/spip/
$this->setPath( $infos['path'] );
}
}
/**
* {@inheritDoc}
**/
public function clear() {
parent::clear();
}
}