Răsfoiți Sursa

add debug git

stany.ferer 3 luni în urmă
părinte
comite
2f4002a440
1 a modificat fișierele cu 38 adăugiri și 23 ștergeri
  1. 38 23
      core/class/git.class.php

+ 38 - 23
core/class/git.class.php

@@ -1,4 +1,4 @@
-<?php 
+<?php
 
 /**
  * Classe git
@@ -14,10 +14,11 @@ class git
      * @param string|null $_string Chaîne à vérifier (facultatif).
      * @return bool Retourne TRUE si aucune erreur n'est détectée, FALSE sinon.
      */
-    public static function checkError(?string $_string = NULL){
+    public static function checkError(?string $_string = NULL)
+    {
         $return = NULL;
-        if($_string != NULL){
-            if(strpos($_string, '-// SUCCESS //-') === TRUE){
+        if ($_string != NULL) {
+            if (strpos($_string, '-// SUCCESS //-') === TRUE) {
                 $return = TRUE;
             } else {
                 return FALSE;
@@ -35,13 +36,22 @@ class git
      * @param string|null $_target Cible Git (par défaut HEAD).
      * @return string Retourne les 10 premiers caractères du hash du commit.
      */
-    public static function getCommitHash($_target = NULL){
-        if($_target == NULL){
+    public static function getCommitHash($_target = NULL)
+    {
+        if ($_target == NULL) {
             $target = "HEAD";
         } else {
-            $target = "origin/".$_target;
+            $target = "origin/" . $_target;
         }
-        return substr(trim(exec('git log --pretty="%H" -n1 ' . $target)), 0, 10);
+        $output = [];
+        $retval = 0;
+        $cmd = 'git log --pretty="%H" -n1 ' . $target;
+        $result = exec($cmd, $output, $retval);
+        // Debug temporaire : affiche la commande, le code retour et la sortie
+        if (debug::isFile("debug")) {
+            echo '<pre style="color:red">CMD: ' . htmlspecialchars($cmd) . "\nRETVAL: $retval\nOUTPUT: " . print_r($output, true) . "\nRESULT: $result</pre>";
+        }
+        return substr(trim($result), 0, 10);
     }
 
     /**
@@ -50,11 +60,12 @@ class git
      * @param string|null $_target Cible Git (par défaut HEAD).
      * @return string Retourne la date du commit formatée (d/m/Y à H:i:s).
      */
-    public static function getCommitDate($_target = NULL){
-        if($_target == NULL){
+    public static function getCommitDate($_target = NULL)
+    {
+        if ($_target == NULL) {
             $target = "HEAD";
         } else {
-            $target = "origin/".$_target;
+            $target = "origin/" . $_target;
         }
         $commitDate = new \DateTime(trim(exec('git log -n1 --pretty=%ci ' . $target)));
         $commitDate->setTimezone(new \DateTimeZone('Europe/Paris'));
@@ -67,11 +78,12 @@ class git
      * @param string|null $_target Cible Git (par défaut HEAD).
      * @return string Retourne le nom de l'auteur du commit.
      */
-    public static function getCommitAuthor($_target = NULL){
-        if($_target == NULL){
+    public static function getCommitAuthor($_target = NULL)
+    {
+        if ($_target == NULL) {
             $target = "HEAD";
         } else {
-            $target = "origin/".$_target;
+            $target = "origin/" . $_target;
         }
         return exec('git log --pretty="%cn" -n1 ' . $target);
     }
@@ -82,11 +94,12 @@ class git
      * @param string|null $_target Cible Git (par défaut HEAD).
      * @return string Retourne le message du commit.
      */
-    public static function getCommitName($_target = NULL){
-        if($_target == NULL){
+    public static function getCommitName($_target = NULL)
+    {
+        if ($_target == NULL) {
             $target = "HEAD";
         } else {
-            $target = "origin/".$_target;
+            $target = "origin/" . $_target;
         }
         return exec('git log --pretty="%s" -n1 ' . $target);
     }
@@ -97,8 +110,9 @@ class git
      * @param string|null $_target Cible Git (facultatif).
      * @return string Retourne le nom de la branche.
      */
-    public static function getBranchName($_target = NULL){
-        if($_target == NULL){
+    public static function getBranchName($_target = NULL)
+    {
+        if ($_target == NULL) {
             return exec('git rev-parse --abbrev-ref HEAD');
         } else {
             return $_target;
@@ -111,13 +125,14 @@ class git
      * @param string|null $_target Cible Git (facultatif).
      * @return void
      */
-    public static function printVersion($_target = NULL){
+    public static function printVersion($_target = NULL)
+    {
         echo sprintf(
             '<h6>%s <span class="badge bg-info">%s</span> <span class="badge bg-success">%s</span></h6>
             <code>%s</code>
-            <div class="media-body pb-3 mb-0 small lh-125">Le %s</div>', 
-            self::getCommitAuthor($_target),         
-            self::getBranchName($_target), 
+            <div class="media-body pb-3 mb-0 small lh-125">Le %s</div>',
+            self::getCommitAuthor($_target),
+            self::getBranchName($_target),
             self::getCommitHash($_target),
             self::getCommitName($_target),
             self::getCommitDate($_target)