diff --git a/Makefile b/Makefile index 0ebcf57..bceb4c4 100644 --- a/Makefile +++ b/Makefile @@ -1,24 +1,37 @@ BASE_REF ?= main -HEAD_REF ?= $(shell git rev-parse HEAD) +HEAD_REF ?= HEAD + +define clone-repo + mkdir -p $(1) + git -C $(1) init + git -C $(1) remote add origin $(2) || true + git -C $(1) fetch origin $(3) + git -C $(1) -c advice.detachedHead=false checkout $(3) + test `git -C $(1) rev-parse HEAD` = $(3) +endef .PHONY: review review: - @echo "Ensuring Cargo.lock is in clean state, not modified" - test -z "$(shell git status --porcelain | grep -E 'M +Cargo.lock')" + $(eval BASE_REF_PARSED := $(shell git rev-parse $(BASE_REF))) + $(eval HEAD_REF_PARSED := $(shell git rev-parse $(HEAD_REF))) @echo "Ensuring current HEAD_REF is not BASE_REF" - test "$(shell git rev-parse $(BASE_REF))" != "$(HEAD_REF)" - @echo "Verifying if any changes happened in Cargo.lock that require review" - test "$(shell git show $(BASE_REF):Cargo.lock | sha256sum)" != "$(shell git show $(HEAD_REF):Cargo.lock | sha256sum)" + test "$(BASE_REF_PARSED)" != "$(HEAD_REF_PARSED)" + @echo "Verifying if any changes happened in Cargo.lock that require review; otherwise, use `git difftool` directly" + test "$(shell git show $(BASE_REF_PARSED):Cargo.lock | sha256sum)" != "$(shell git show $(HEAD_REF_PARSED):Cargo.lock | sha256sum)" $(eval TEMP_REPO := $(shell mktemp -d)) - git -C $(TEMP_REPO) init + $(call clone-repo,$(TEMP_REPO),$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))),$(BASE_REF_PARSED)) + # Unstage current commit before refreeze + git -C $(TEMP_REPO) reset --hard 'HEAD^1' # Fetch files for BASE_REF - git show $(BASE_REF):Cargo.lock > $(TEMP_REPO)/Cargo.lock - CARGO_HOME=$(TEMP_REPO)/cargo-home cargo fetch + cd $(TEMP_REPO) && CARGO_HOME=$(TEMP_REPO)/cargo-home cargo fetch git -C $(TEMP_REPO) add . git -C $(TEMP_REPO) commit --no-gpg-sign -m "base ref: $(BASE_REF)" + # git -C $(TEMP_REPO) ls-files -z | (cd $(TEMP_REPO); xargs -0 -n1 rm) + git -C $(TEMP_REPO) fetch origin $(HEAD_REF_PARSED) + git -C $(TEMP_REPO) merge --no-commit $(HEAD_REF_PARSED) + rm -rf $(TEMP_REPO)/cargo-home # Fetch files for HEAD_REF - git show $(HEAD_REF):Cargo.lock > $(TEMP_REPO)/Cargo.lock - CARGO_HOME=$(TEMP_REPO)/cargo-home cargo fetch + cd $(TEMP_REPO) && CARGO_HOME=$(TEMP_REPO)/cargo-home cargo fetch git -C $(TEMP_REPO) add -A . git -C $(TEMP_REPO) difftool HEAD || true - rm -rf $(TEMP_REPO) + # rm -rf $(TEMP_REPO)