2024-01-18 23:01:44 +00:00
|
|
|
BASE_REF ?= main
|
2024-01-18 23:47:09 +00:00
|
|
|
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
|
2024-01-18 23:01:44 +00:00
|
|
|
|
|
|
|
.PHONY: review
|
|
|
|
review:
|
2024-01-18 23:47:09 +00:00
|
|
|
$(eval BASE_REF_PARSED := $(shell git rev-parse $(BASE_REF)))
|
|
|
|
$(eval HEAD_REF_PARSED := $(shell git rev-parse $(HEAD_REF)))
|
2024-01-18 23:01:44 +00:00
|
|
|
@echo "Ensuring current HEAD_REF is not BASE_REF"
|
2024-01-18 23:47:09 +00:00
|
|
|
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)"
|
2024-01-18 23:01:44 +00:00
|
|
|
$(eval TEMP_REPO := $(shell mktemp -d))
|
2024-01-18 23:47:09 +00:00
|
|
|
$(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'
|
2024-01-18 23:01:44 +00:00
|
|
|
# Fetch files for BASE_REF
|
2024-01-18 23:47:09 +00:00
|
|
|
cd $(TEMP_REPO) && CARGO_HOME=$(TEMP_REPO)/cargo-home cargo fetch
|
2024-01-18 23:52:33 +00:00
|
|
|
echo "cargo-home/registry/cache" >> $(TEMP_REPO)/.gitignore
|
|
|
|
echo "cargo-home/registry/index" >> $(TEMP_REPO)/.gitignore
|
|
|
|
echo "cargo-home/registry/CACHEDIR.TAG" >> $(TEMP_REPO)/.gitignore
|
2024-01-18 23:01:44 +00:00
|
|
|
git -C $(TEMP_REPO) add .
|
|
|
|
git -C $(TEMP_REPO) commit --no-gpg-sign -m "base ref: $(BASE_REF)"
|
2024-01-18 23:47:09 +00:00
|
|
|
# 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)
|
2024-01-18 23:52:33 +00:00
|
|
|
rm -rf $(TEMP_REPO)/cargo-home/registry/src
|
2024-01-18 23:01:44 +00:00
|
|
|
# Fetch files for HEAD_REF
|
2024-01-18 23:47:09 +00:00
|
|
|
cd $(TEMP_REPO) && CARGO_HOME=$(TEMP_REPO)/cargo-home cargo fetch
|
2024-01-18 23:01:44 +00:00
|
|
|
git -C $(TEMP_REPO) add -A .
|
2024-01-18 23:55:39 +00:00
|
|
|
git -C $(TEMP_REPO) difftool --diff-filter=r HEAD || true
|
2024-01-18 23:47:09 +00:00
|
|
|
# rm -rf $(TEMP_REPO)
|