0

I'm using :

<?php
ob_start();
$vtag = shell_exec('git describe --tags');
if( is_null($vtag) ) { $vtag =""; }
ob_end_clean();
?>

To get the version of my GIT controlled project I'm using un-annotated tags and I can get the command to show the correct info when I run it from GIT CMD in windows 8.1.

The PHP manual (user contributed section) suggests using Ob_start/end_clean() to ensure we get output from std console. But its not producing any output (or error output). any idea what the problem is here??

Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268
Flim Flam
  • 197
  • 4
  • 15
  • What have you done to debug your issue? Do you know for certain if your code is being called or not? – Mort May 04 '18 at 00:35
  • i tried initially with exec() then shell_exec. All i tried so far is removing the 'if' condition to see if it was actually returning null – Flim Flam May 04 '18 at 00:41
  • Add the following code right after the opening `php` tag - ` – Pedro Lobito May 04 '18 at 00:48
  • the ini_set directives arent producing any errors- the whoami says: nt authority\system. Just had a thought; im running this from an include in the footer of my project so ill try this in the header before any other output – Flim Flam May 04 '18 at 01:01

2 Answers2

1

I suggest to use some existing library for this task - there is no point to reinvent the wheel again. For example cpliakas/git-wrapper:

$gitWrapper = new GitWrapper();
echo $gitWrapper->git('describe --tags', '/path/to/repository');

$repository = $gitWrapper->workingCopy('/path/to/repository'); 
echo $repository->tag();
rob006
  • 21,383
  • 5
  • 53
  • 74
-1

Found this article which helped me solve the problem:

Just to help anyone else with the same issue; this is what i used :

$vtag = (string) shell_exec('C:\\PROGRA~1\\Git\\bin\\git describe --tags');

The problem is that exec() needs the path to the executable in the bin directory and more importantly because the user in a WAMP environment is Apache (www) directory which does not have GIT in its path. Remember also (i initially forgot) to escape backslashes on Windows.

Hope this helps everyone else. Cheers!

Flim Flam
  • 197
  • 4
  • 15
  • Still dont see why the downvote! the article pointed to by the other answer did not help in my situation neither did any other articles i read on SO or elsewhere until i found the article which helped. Windows users using WAMPServer would almost definitely find it useful. I dont use SO to needlessly Point-score off other users. – Flim Flam May 04 '18 at 09:11