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

+ 5 - 6
core/class/git.class.php

@@ -50,13 +50,12 @@ class git
             $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];
+            exec($cmd, $output, $retval);
+            if (isset($output[0]) && preg_match('/^([a-f0-9]{40})/', $output[0], $matches)) {
+                return substr($matches[1], 0, 10);
+            } else {
+                return "<pre>DISTANT ($_target): N/A</pre>";
             }
-            return substr(trim($hash), 0, 10);
         }
     }
 

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

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