Skip to content
Snippets Groups Projects
Commit 78d54196 authored by Patrick Baudin's avatar Patrick Baudin
Browse files

[Headers] adds targets related to commits

parent 343a7815
No related branches found
No related tags found
No related merge requests found
......@@ -204,6 +204,88 @@ headers: $(FRAMAC_HDRCK)
$(error "Please set HEADER_SPEC variable to a file containing the header specification.")
else
ifneq ($(HDRCK.HAS_GIT),)
define HDRCK.file-list-from-git-diff
$(GIT) diff --name-status $(1) | $(GREP) -v "^D" | $(SED) "s/^.[ \t]*//" | $(TR) '\n' '\000' | $(HDRCK.FILE_ATTR)
endef
HDRCK.main-targets=check-headers headers
define HDRCK.file-list-filter-with-git-diff
HDRCK.$(1)-filter-targets=$$(addsuffix .$(1),$$(HDRCK.main-targets))
.PHONY: $(LINT.$(1)-filter-targets)
$$(HDRCK.$(1)-filter-targets):: HDRCK.SPEC=$$(call HDRCK.file-list-from-git-diff,$(2))
$$(HDRCK.$(1)-filter-targets):: %.$(1) : $(3) %
@echo [HDRCK] Done: HDRCK_DIFF=\"$(2)\" make $$(basename $$@)
@echo [HDRCK] checked file list:
$$(GIT) diff --name-status $(2)
endef
ifneq ($(HEADER_DIFF),)
$(info [HDRCK] Looking at files modified from branch/commit: '$(HEADER_DIFF)')
HDRCK.SPEC=$(call LINT.file-list-from-git-diff,$(HEADER_DIFF))
$(info $(HEADER.FILE_LIST))
endif # $(HEADER_DIFF)
#### rules for make <headers-target>.before-push
## looks at files modified from origin/$(git branch --show-current) and checks that there is no staged nor unstaged files
PHONY: HDRCK.checked-unmodified-ok
HDRCK.checked-unmodified-ok:
$(eval HDRCK.checked-unmodified := $(shell $(GIT) diff --name-status HEAD | $(WC) -l))
if [ 0 != $(HDRCK.checked-unmodified) ]; then \
echo "[HDRCK] Staged or unstaged files=$(HDRCK.checked-unmodified):"; \
$(GIT) diff --name-status HEAD; \
echo "[HDRCK] Error: may check some staged or unstaged file versions" ; \
exit 1; \
fi;
$(eval $(call HDRCK.file-list-filter-with-git-diff,before-push,--cached origin/$(shell git branch --show-current),HDRCK.checked-unmodified-ok))
#### rules for make <headers-target>.unstaged
## looks at unstaged files
$(eval $(call HDRCK.file-list-filter-with-git-diff,unstaged, ))
#### rules for make <headers-target>.before-commit
## looks at staged files and checks that there is no unstaged files
PHONY: HDRCK.checked-unstaged-ok
HDRCK.checked-unstaged-ok:
$(eval HDRCK.checked-unstaged := $(shell $(GIT) diff --name-status | $(WC) -l))
if [ 0 != $(HDRCK.checked-unstaged) ]; then \
echo "[HDRCK] Unstaged files=$(HDRCK.checked-unstaged):"; \
$(GIT) diff --name-status ; \
echo "[HDRCK] Error: may check some unstaged version files version." ; \
exit 1; \
fi;
$(eval $(call HDRCK.file-list-filter-with-git-diff,before-commit,--cached HEAD,HDRCK.checked-unstaged-ok))
#### rules for make <headers-target>.before-commit-a
## looks at unstaged and staged files
$(eval $(call HDRCK.file-list-filter-with-git-diff,before-commit-a,HEAD,))
#### rules for make <headers-target>.before-commit-a--ammend
## looks at unstaged, staged and previously committed files
$(eval $(call HDRCK.file-list-filter-with-git-diff,before-commit-a--ammend,HEAD~1,))
#### rules for make <headers-target>.before-commit--amend
## looks at staged and previously committed files and checks that there is no unstaged files
$(eval $(call HDRCK.file-list-filter-with-git-diff,before-commit--ammend,HEAD~1,HDRCK.checked-unstaged-ok))
#### rules for make <headers-target>.previous-commit
## looks at files of the last commit and checks that there is no staged nor unstaged files
$(eval $(call HDRCK.file-list-filter-with-git-diff,previous-commit,HEAD~1,HDRCK.checked-unmodified-ok))
endif # $(HDRCK.HAS_GIT)
.PHONY: check-headers
check-headers: $(FRAMAC_HDRCK)
$(HDRCK.SPEC) | $(HDRCK.CMD) $(HDRCK.OPTS) $(HDRCK_EXTRA)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment