Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

write git commit version info in app's footer

Tags:

git

php

mysql

I'm using git for version control for this one mysql/php project and I have virtual hosts set up in Apache where the origin/master is the default web site (port 80) and a different virtual host, with different ports (8081, 8082, 8083, etc.) for each dev's working copy folder (so we can view each other's work on the fly)... using git (hooks?),

how do I set it up so that for each time someone commits & pushes it writes human readable version info (timestamp, committer, comment, repository, branch, etc.) to a HTML file? I'm hoping to throw that info in the footer of every page so its even easier to keep track of who's work/copy we're viewing at a given time.

like image 322
crashintoty Avatar asked Oct 19 '22 14:10

crashintoty


1 Answers

Could add this to the footer as long as you have access to the exec() function:

exec('git branch | sed -n "/\* /s///p"', $output);
exec('git --no-pager show --summary', $output2);

$current_commit = [
    'branch' => $output[0],
    'commit' => array_shift($output2),
    'author' => array_shift($output2),
    'date' => array_shift($output2),
    'message' => implode('', $output2),
];

echo '<pre>' . print_r($current_commit,true) . '</pre>';

Will give you an output something like this:

Array
(
    [branch] => master
    [commit] => commit 12345f424909eda4db1f7a811eb9d3a7e7112345
    [author] => Author: Test Tester <[email protected]>
    [date] => Date:   Thu Feb 11 14:13:51 2016 -0500
    [message] =>     small update
)
like image 148
Pitchinnate Avatar answered Nov 15 '22 06:11

Pitchinnate