[TikiWiki-commits] [Git][tikiwiki/tiki][master] [ENH] Add Git commit info to tiki-admin.php?page=general for Git-based installs

Benoit Grégoire (@benoitg) via TikiWiki-cvs <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <693061b337d90_2b4e95d00728cb@gitlab-sidekiq-low-urgency-cpu-bound-v2-76d8cdf8fc-7k79d.mail>

Benoit Grégoire pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
a2dfd107 by Sandeep D at 2025-12-03T16:03:42+00:00
[ENH] Add Git commit info to tiki-admin.php?page=general for Git-based installs
---
* [REF] Refactor getGitDetails method

* [REF] Refactor Git information retrieval

* [ENH] Add Git commit info to tiki-admin.php?page=general for Git-based installs

This merge request enhances the admin interface (`tiki-admin.php?page=general`) to display Git commit details if Tiki is installed via a Git clone.

**Features Implemented:**
- Extended the "Tiki version" banner to include:
  - Current Git branch name
  - Short Git commit hash (with link to full commit on GitLab)
  - Git commit date (formatted using `tiki_short_datetime`)
- Git commit shown as: `<BRANCH>:<COMMIT> from <COMMIT DATE>`

See merge request tikiwiki/tiki!9030

- - - - -


4 changed files:

- lib/gitlib.php
- modules/mod-func-git_detail.php
- templates/admin/include_general.tpl
- tiki-admin.php


Changes:

=====================================
lib/gitlib.php
=====================================
@@ -178,7 +178,7 @@ class GitLib extends TikiLib
         $cachelib = TikiLib::lib('cache');
         $object = null;
 
-        if (is_dir('.git') && is_readable('.git')) {
+        if ($this->isGitInstall()) {
             if (! $cachelib->isCached('.git', 'head')) {
                 $cachelib->cacheItem('.git', md5_file('.git/HEAD'), 'head');
             } else {
@@ -208,6 +208,47 @@ class GitLib extends TikiLib
         return $object;
     }
 
+    /**
+     * Check if this is a Git-based installation.
+     *
+     * @return bool
+     */
+    public function isGitInstall()
+    {
+        return is_dir('.git') && is_readable('.git');
+    }
+
+    /**
+     * Get git info with error handling.
+     * This method safely wraps get_info() and handles exceptions.
+     * Should only be called after verifying isGitInstall() returns true.
+     *
+     * @return array ['content' => array, 'error' => string]
+     */
+    public function getGitDetails()
+    {
+        include_once('lib/setup/twversion.class.php');
+        $TWV = new TWVersion();
+        $version = $TWV->getVersion();
+
+        $error = '';
+        $content = [];
+
+        try {
+            $content = $this->get_info();
+        } catch (Exception $e) {
+            $error = $e->getMessage();
+        } catch (Error $e) {
+            $error = $e->getMessage();
+        } catch (Throwable $e) {
+            $error = $e->getMessage();
+        }
+
+        $content['version'] = $version;
+
+        return ['content' => $content, 'error' => $error];
+    }
+
     /**
      * Return structured array for object informed as parameter.
      *


=====================================
modules/mod-func-git_detail.php
=====================================
@@ -31,32 +31,15 @@ function module_git_detail($mod_reference, $module_params)
     $smarty = TikiLib::lib('smarty');
     /** @var GitLib $gitlib */
     $gitlib = TikiLib::lib('git');
-    $error = '';
-    $content = [];
-    include_once('lib/setup/twversion.class.php');
-    $TWV = new TWVersion();
-    $version = $TWV->getVersion();
 
-    try {
-        $content = $gitlib->get_info();
-    } catch (Exception $e) {
-        $error = $e->getMessage();
-    } catch (Error $e) {
-        $error = $e->getMessage();
-    } catch (Throwable $e) {
-        $error = $e->getMessage();
+    if (! $gitlib->isGitInstall()) {
+        $smarty->assign('error', tra('Not a Git installation'));
+        $smarty->assign('content', []);
+        return;
     }
 
-    if (empty($content)) {
-        $content = [
-            'version' => $version,
-            'commit' => 'N/A',
-            'date' => 'N/A',
-            'branch' => 'N/A',
-            'remote' => 'N/A',
-        ];
-    }
+    $result = $gitlib->getGitDetails();
 
-    $smarty->assign('error', $error);
-    $smarty->assign('content', $content);
+    $smarty->assign('error', $result['error']);
+    $smarty->assign('content', $result['content']);
 }


=====================================
templates/admin/include_general.tpl
=====================================
@@ -13,6 +13,16 @@
             <fieldset>
                 <legend class="h3">{tr}Release check{/tr}</legend>
                 {include file='admin/version_check.tpl'}
+                {remarksbox type="info" title="{tr}Tiki version{/tr}"}
+                    <div class="adminoptionbox">
+                        <strong>{tr}Tiki version: {/tr}</strong> {$tiki_version}
+                    </div>
+                    {if ! empty($git_details)}
+                        <div class="adminoptionbox">
+                            <strong>{tr}Git Information:{/tr}</strong> {$git_details.branch}: <a target="_blank" class="wiki external" href="https://gitlab.com/tikiwiki/tiki/-/commit/{$git_details.commit.hash}"><cite>{$git_details.commit.hash|substring:0:8}</cite></a>{icon name='link-external'} {tr}from{/tr} {$git_details.committer.date|tiki_short_datetime}
+                        </div>
+                    {/if}
+                {/remarksbox}
             </fieldset>
             <fieldset>
                 <legend class="h3">{tr}Site identity{/tr}</legend>


=====================================
tiki-admin.php
=====================================
@@ -369,9 +369,14 @@ if ($prefs['feature_version_checks'] == 'y' || $forcecheck) {
     $versionUtils = new Tiki_Version_Utils();
     $upgrades = $versionUtils->checkUpdatesForVersion($TWV->version);
 
+    $gitlib = TikiLib::lib('git');
+    $gitDetails = $gitlib->isGitInstall() ? $gitlib->getGitDetails()['content'] : [];
+
     $smarty->assign('upgrade_messages', $upgrades);
+    $smarty->assign('git_details', $gitDetails);
 } else {
     $smarty->assign('upgrade_messages', []);
+    $smarty->assign('git_details', []);
 }
 
 // SSL setup



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/a2dfd107ceb02a6952c33d6cd12b0474e3cce357

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/a2dfd107ceb02a6952c33d6cd12b0474e3cce357
You're receiving this email because of your account on gitlab.com.

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.