我正在尝试编写一个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
Run Code Online (Sandbox Code Playgroud)
但是,我所经历的是,如果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
Run Code Online (Sandbox Code Playgroud)
或者
.PHONY: check-git-clean
check-git-clean: other-target
git diff-index --quiet HEAD
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
959 次 |
| 最近记录: |