Skip to content

Instantly share code, notes, and snippets.

@fatih
Created March 24, 2016 10:51
Show Gist options
  • Save fatih/9585f9bf2a6548461847 to your computer and use it in GitHub Desktop.
Save fatih/9585f9bf2a6548461847 to your computer and use it in GitHub Desktop.
Makefile
ifeq ($(strip $(shell git status --porcelain 2>/dev/null)),)
GIT_TREE_STATE=clean
else
GIT_TREE_STATE=dirty
endif
all: build
build:
@echo "==> Building the project"
release: check
@echo "==> Releasing the project"
check:
ifeq ($(GIT_TREE_STATE),dirty)
$(error git state is not clean)
endif
.PHONY: all build release
@broady
Copy link

broady commented Oct 2, 2018

Just came up with this one-liner, what do you think?

GIT_TREE_STATE=$(shell (git status --porcelain | grep -q .) && echo dirty || echo clean)

@fatih
Copy link
Author

fatih commented Oct 2, 2018

Wow, just saw this gist here :D Thanks @broady. I think you're one liner is much better than what I have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment