Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add git tools #7

Open
jdarwood007 opened this issue Mar 30, 2023 · 1 comment
Open

Add git tools #7

jdarwood007 opened this issue Mar 30, 2023 · 1 comment

Comments

@jdarwood007
Copy link
Owner

jdarwood007 commented Mar 30, 2023

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
Copy link
Owner Author

jdarwood007 commented Mar 30, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant