jdarwood007 / smfmod_devtools

Tool to assist with developing customizations for SMF
https://custom.simplemachines.org/index.php?mod=4358
BSD 3-Clause "New" or "Revised" License
3 stars 0 forks source link

Add git tools #7

Open jdarwood007 opened 1 year ago

jdarwood007 commented 1 year ago

Add git information. Add a way to select what packages we want to see git status for

I already do this on my git checkout for SMF

Screen Shot 2023-03-29 at 6 41 43 PM

I should add a sections saying "clean" or "modified" to indicate if files are all clean or modified. Should be easy enough with checking the git status --porcelain output. This will require shell_exec permissions.

Screen Shot 2023-03-29 at 6 53 51 PM
jdarwood007 commented 1 year ago

Keeping track of my current notes. The current method is add to Settings.php:

define('GITSITE', dirname(__FILE__));
require_once('smf_git_info.php');

Then smf_git_info.php contains

register_shutdown_function('__pseudo_smf_git_handle');

function __pseudo_smf_git_handle()
{
    $contents = ob_get_contents();
    ob_clean();

    if (defined('GITSITE') && php_sapi_name() != 'cli')
    {
        chdir(GITSITE);

        // Current branch
        $smf_git_current_branch = rtrim(shell_exec("git status | grep 'On branch' | awk '{print $3}'") ?? '');
        $smf_git_current_revision = rtrim(shell_exec('git log -n1 | grep -E \'^commit [A-Za-z0-9]{40}$\' | awk \'{print $2}\'') ?? '');
        $smf_git_modified_files = rtrim(shell_exec('git status --porcelain') ?? '');

        $contents = preg_replace('~Simple Machines</a></li>~i', 'Simple Machines</a></li>
                <li class="smalltext">SMF [Git Branch: ' . $smf_git_current_branch . ' | Git Revision: ' . substr($smf_git_current_revision, -7) . ' | ' . (!empty($smf_git_modified_files) ? 'Modified Files' : 'Clean Files') . ']</li>', $contents);
    }

    echo $contents;
}

Will need cleanup for going into tools.