抓取项目的当前提交并显示它
Issue
I was working on a project where QAs report bugs that already fixed. So many time, it turn out that QAs don’t have our latest code.
Solution
Now, I’m thinking to grab the current commit and display it in the console
or on other page for references between us QA, and Developers.
Tried
In CLI, to get the latest commit, I just to do this
git rev-parse --verify HEAD
I’ve tried create a PHP function, and call it.
public function info(){
return str_replace('
','', json_encode(shell_exec('git rev-parse --verify HEAD')));
}
Result
It works fine on my Mac, but on my QA set up, they got null
.
Questions
What did I do wrong ?
Is there another way to do this ?
I’m open to any suggestions at the moment. :)
问题 h1>
我正在开展一个QAs报告错误的项目 固定。 很多时候,事实证明QAs没有我们最新的代码。 p>
解决方案 h1>
现在,我正在考虑获取当前提交并将其显示在 在CLI中,要获取最新的提交,我只是这样做 p>
我尝试创建一个PHP函数,然后调用它。 p>
它在我的Mac上工作正常,但在我的 QA设置,他们得到 我做错了什么 ? p>
还有其他办法吗? p>
我现在对任何建议持开放态度。 :) p>
div>控制台中 code>或在其他页面上提供我们QA和开发人员之间的参考。 p>
尝试 h1>
git rev-parse --verify HEAD
code> pre>
public function info(){
return str_replace('
','',json_encode(shell_exec('git rev-parse --verify HEAD'))) ;
}
code> pre>
结果 h1>
null code>。 p>
问题 h1>
git
expects to be called from Git working directory tree as presumably it was when you executed it from the command line. PHP scripts initially set the PWD
parent working directory environment variable to the directory in which the script is located and that's the same for command execution (exec, shell_exec, system, passthru). You can change directory from within PHP using chdir or change the command to
cd /path/to/git/repo && git rev-parse --verify HEAD