X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=www%2Fplugins-dist%2Fsvp%2Fteleporter%2Fgit.php;h=ec222105111b141cd44c875e87976645807c3679;hb=4f443dce95ff6f8221c189880a70c74ce1c1f238;hp=085ba7247b0a9808fda54ba83c8cde86a39291dc;hpb=4a628e9b277d3617535f99d663ca79fa2e891177;p=lhc%2Fweb%2Fwww.git diff --git a/www/plugins-dist/svp/teleporter/git.php b/www/plugins-dist/svp/teleporter/git.php index 085ba724..ec222105 100644 --- a/www/plugins-dist/svp/teleporter/git.php +++ b/www/plugins-dist/svp/teleporter/git.php @@ -1,15 +1,19 @@ 'assoc')); - if (!$infos){ - spip_log("Suppression de $dest qui n'est pas au format GIT","teleport"); + $branche = (isset($options['branche']) ? $options['branche'] : 'master'); + if (is_dir($dest)) { + $infos = teleporter_git_read($dest, array('format' => 'assoc')); + if (!$infos) { + spip_log("Suppression de $dest qui n'est pas au format GIT", "teleport"); $old = teleporter_nettoyer_vieille_version($dest); - } - elseif ($infos['source']!==$source) { - spip_log("Suppression de $dest qui n'est pas sur le bon repository GIT","teleport"); + } elseif ($infos['source'] !== $source) { + spip_log("Suppression de $dest qui n'est pas sur le bon repository GIT", "teleport"); $old = teleporter_nettoyer_vieille_version($dest); - } - elseif (!isset($options['revision']) - OR $options['revision']!=$infos['revision']){ - $command = "git checkout ".escapeshellarg($branche); - teleporter_git_exec($dest,$command); - $command = "git pull --all"; - teleporter_git_exec($dest,$command); - - if (isset($options['revision'])){ - $command = "git checkout ".escapeshellarg($options['revision']); - teleporter_git_exec($dest,$command); - } - else { - $command = "git checkout ".escapeshellarg($branche); - teleporter_git_exec($dest,$command); + } elseif (!isset($options['revision']) + or $options['revision'] != $infos['revision'] + ) { + $command = _GIT_COMMAND . " checkout " . escapeshellarg($branche); + teleporter_git_exec($dest, $command); + $command = _GIT_COMMAND . " pull --all"; + teleporter_git_exec($dest, $command); + + if (isset($options['revision'])) { + $command = _GIT_COMMAND . " checkout " . escapeshellarg($options['revision']); + teleporter_git_exec($dest, $command); + } else { + $command = _GIT_COMMAND . " checkout " . escapeshellarg($branche); + teleporter_git_exec($dest, $command); } - } - else { - spip_log("$dest deja sur GIT $source Revision ".$options['revision'],"teleport"); + } else { + spip_log("$dest deja sur GIT $source Revision " . $options['revision'], "teleport"); } } - if (!is_dir($dest)){ - $command = "git clone "; - $command .= escapeshellarg($source)." ".escapeshellarg($dest); - teleporter_git_exec($dest,$command); - if (isset($options['revision'])){ - $command = "git checkout ".escapeshellarg($options['revision']); - teleporter_git_exec($dest,$command); + if (!is_dir($dest)) { + $command = _GIT_COMMAND . " clone "; + $command .= escapeshellarg($source) . " " . escapeshellarg($dest); + teleporter_git_exec($dest, $command); + if (isset($options['revision'])) { + $command = _GIT_COMMAND . " checkout " . escapeshellarg($options['revision']); + teleporter_git_exec($dest, $command); } } // verifier que tout a bien marche $infos = teleporter_git_read($dest); - if (!$infos) return false; + if (!$infos) { + return false; + } return true; } @@ -80,7 +83,7 @@ function teleporter_git_dist($methode,$source,$dest,$options=array()){ * Lire l'état GIT du repository * * Retourne les informations GIT d'un répertoire donné - * + * * @param string $dest * Chemin du répertoire à tester * @param array $options @@ -93,43 +96,47 @@ function teleporter_git_dist($methode,$source,$dest,$options=array()){ * -- revision : Révision du dépot * -- dest : Répertoire du dépot. */ -function teleporter_git_read($dest, $options=array()) { +function teleporter_git_read($dest, $options = array()) { - if (!is_dir("$dest/.git")) + if (!is_dir("$dest/.git")) { return ""; + } $curdir = getcwd(); chdir($dest); - exec("git remote -v",$output); - $output = implode("\n",$output); + exec(_GIT_COMMAND . " remote -v", $output); + $output = implode("\n", $output); $source = ""; - if (preg_match(",(\w+://.*)\s+\(fetch\)$,Uims",$output,$m)) + if (preg_match(",(\w+://.*)\s+\(fetch\)$,Uims", $output, $m)) { $source = $m[1]; - elseif (preg_match(",([^@\s]+@[^:\s]+:.*)\s+\(fetch\)$,Uims",$output,$m)) + } elseif (preg_match(",([^@\s]+@[^:\s]+:.*)\s+\(fetch\)$,Uims", $output, $m)) { $source = $m[1]; + } - if (!$source){ + if (!$source) { chdir($curdir); + return ""; } $source = $m[1]; - exec("git log -1",$output); - $hash = explode(" ",reset($output)); + exec(_GIT_COMMAND . " log -1", $output); + $hash = explode(" ", reset($output)); $hash = end($hash); // [TODO] lire la branche ? chdir($curdir); - if (preg_match(",[^0-9a-f],i",$hash)) + if (preg_match(",[^0-9a-f],i", $hash)) { return false; + } return array( 'source' => $source, - 'revision' => substr($hash,0,7), + 'revision' => substr($hash, 0, 7), 'dest' => $dest ); } @@ -144,10 +151,26 @@ function teleporter_git_read($dest, $options=array()) { * Commande à exécuter * @return void */ -function teleporter_git_exec($dest,$command) { - spip_log("{$dest}:{$command}","teleport"); +function teleporter_git_exec($dest, $command) { + spip_log("{$dest}:{$command}", "teleport"); $curdir = getcwd(); chdir($dest); exec($command); chdir($curdir); } + + +/** + * Tester si la commande 'git' est disponible + * + * @return bool + * true si on peut utiliser la commande svn + **/ +function teleporter_git_tester() { + static $erreurs = null; + if (is_null($erreurs)) { + exec(_GIT_COMMAND . " --version", $output, $erreurs); + } + + return !$erreurs; +}