stany.ferer 3 月之前
父節點
當前提交
55de511540
共有 2 個文件被更改,包括 25 次插入7 次删除
  1. 15 7
      core/class/git.class.php
  2. 10 0
      core/views/pages/cms.testGit.php

+ 15 - 7
core/class/git.class.php

@@ -41,15 +41,23 @@ class git
         if ($_target == NULL) {
             // Commit local HEAD
             $cmd = 'git log --pretty="%H" -n1 HEAD';
+            $output = [];
+            $retval = 0;
+            $result = exec($cmd, $output, $retval);
+            return substr(trim($result), 0, 10);
         } else {
-            // On met à jour les refs distantes avant de lire origin/$_target
-            exec('git fetch --all --prune');
-            $cmd = 'git log --pretty="%H" -n1 origin/' . $_target;
+            // Hash du commit distant en temps réel
+            $cmd = 'git ls-remote origin "refs/heads/' . $_target . '"';
+            $output = [];
+            $retval = 0;
+            $result = exec($cmd, $output, $retval);
+            // $result ou $output[0] = "<hash>\trefs/heads/branch"
+            $hash = '';
+            if (!empty($output) && strpos($output[0], '\t') !== false) {
+                $hash = explode("\t", $output[0])[0];
+            }
+            return substr(trim($hash), 0, 10);
         }
-        $output = [];
-        $retval = 0;
-        $result = exec($cmd, $output, $retval);
-        return substr(trim($result), 0, 10);
     }
 
     /**

+ 10 - 0
core/views/pages/cms.testGit.php

@@ -0,0 +1,10 @@
+<?php
+
+echo "<h3>Local</h3>";
+echo git::getCommitHash();
+
+echo "<h3>Demo</h3>";
+echo git::getCommitHash("preprod");
+
+echo "<h3>Prod</h3>";
+echo git::getCommitHash("master");