douzhang2092 2016-09-29 14:08
浏览 19
已采纳

抓取项目的当前提交并显示它

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. :)

  • 写回答

1条回答 默认 最新

  • dphe5602 2016-09-29 14:21
    关注

    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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)