简体   繁体   English

如何从Gruntfile.js获取最新的提交哈希?

[英]How can I get the latest commit hash from Gruntfile.js?

What I'm trying now is to use shelljs, but for some reason shell.exec('git rev-parse HEAD') just hangs. 我现在正在尝试使用shelljs,但是由于某种原因shell.exec('git rev-parse HEAD')只是挂起。

This is my code: 这是我的代码:

function getLatestCommit() {
    return shell.exec("git rev-parse HEAD", {
        silent: true,
    }).output.trim().substr(0, 7);
}

Does anyone know any other way to achieve this? 有谁知道实现此目标的其他方法吗?

I'm working on windows... 我正在Windows上工作...

shell.exec uses a callback. shell.exec使用回调。 You're passing a parameter to it, but not utilizing the callback: 您正在向其传递参数,但未利用回调:

var shell = require('child_process');

function getLatestCommit() {
    shell.exec("git rev-parse HEAD", { silent: true }, function(error, stdout, stderr) {
        console.log(error, stdout);
    });
}
getLatestCommit();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM