在Makefile中使用ifneq检查当前git分支

时间:2016-10-11 18:10:09

标签: git makefile

我试图让我的makefile检查它是否在正确的分支上运行,如果没有则抛出错误。

我使用function fibonacci(num) { return Array.apply(null, Array(num)).reduce(function(acc, curr, idx) { return idx > 2 ? acc.concat(acc[idx-1] + acc[idx-2]) : acc; }, [0, 1, 1]); } console.log(fibonacci(10));来比较它们和ifneq来获取已检出的分支,但它不会将它们视为相等。我该如何解决这个问题?

现在代码看起来像这样:

git rev-parse --abbrev-ref HEAD

感谢。

1 个答案:

答案 0 :(得分:8)

没有像$(git ...)这样的make函数,因此变量引用扩展为空字符串。你一直在跑:

ifneq (, master)

总是如此。

您想使用shell GNU make函数:

ifneq ($(shell git rev-parse --abbrev-ref HEAD),master)