bash - Makefile 目标检查干净的 git diff
问题描述
我正在尝试编写一个Makefile
目标,以检查在运行另一个目标后运行它的 git 存储库中是否没有未提交的更改。
这是我到目前为止所拥有的:
check-git-clean: other-target
ifneq ($(shell git diff-index --quiet HEAD; echo $$?), 0)
$(error "There are uncomitted changes after running make other-target")
endif
但是,我遇到的是,如果other-target
未提交的原因发生变化,ifneq
则不会捕获它。另一方面,如果在我运行之前make check-git-clean
已经有未提交的更改,那么ifneq
确实会捕获它。
所以,在某种程度上,它几乎就像ifneq
是在“之前”运行,make other-target
但我得到的 CLI 输出(回显)的顺序是正确的。
我想知道我怎样才能做到这一点。
解决方案
我可以推荐git diff --exit-code
直接使用吗?
.PHONY: check-git-clean
check-git-clean: other-target
git diff --quiet
或者
.PHONY: check-git-clean
check-git-clean: other-target
git diff-index --quiet HEAD
推荐阅读
- r - 检查非唯一字符的字符串模式
- java - Maven:“找不到工件包:jar:1.0-SNAPSHOT”?
- javascript - Vue Scoped Slots 组件和插槽之间的双向数据绑定
- jmeter - 如何在 JMeter 中使用 JGit 添加 ssh 密钥
- powershell - PowerShell 的测试路径超时
- r - 创建直方图“无效的'中断'数量”时R中的错误
- javascript - 防止用户在 javascript 的文本输入中输入重复的条目
- linux - openMp 和核心数 vs cpus
- angular - 如何将输入变量传递给服务Angular
- ruby-on-rails - 如何使用“连接”从两个表中检索数据?