From b5c7332182a1dacc17713d44f502b3ec85b2c097 Mon Sep 17 00:00:00 2001 From: Philipp AUER Date: Sun, 7 Apr 2024 16:43:04 +0200 Subject: [PATCH] feat: check if inside of git repository before building (#4363) * feat: check if inside of git repository before building * pokemon_expansion -> pokeemerald-expansion --------- Co-authored-by: sbird Co-authored-by: Eduardo Quezada --- Makefile | 7 +++++-- check_history.sh | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100755 check_history.sh diff --git a/Makefile b/Makefile index 39b246ab6b..6edd1bf06d 100644 --- a/Makefile +++ b/Makefile @@ -187,7 +187,7 @@ MAKEFLAGS += --no-print-directory # Secondary expansion is required for dependency variables in object rules. .SECONDEXPANSION: -.PHONY: all rom clean compare tidy tools check-tools mostlyclean clean-tools clean-check-tools $(TOOLDIRS) $(CHECKTOOLDIRS) libagbsyscall agbcc modern tidymodern tidynonmodern check +.PHONY: all rom clean compare tidy tools check-tools mostlyclean clean-tools clean-check-tools $(TOOLDIRS) $(CHECKTOOLDIRS) libagbsyscall agbcc modern tidymodern tidynonmodern check history infoshell = $(foreach line, $(shell $1 | sed "s/ /__SPACE__/g"), $(info $(subst __SPACE__, ,$(line)))) @@ -254,7 +254,10 @@ endif AUTO_GEN_TARGETS := -all: rom +all: history rom + +history: + @bash ./check_history.sh tools: $(TOOLDIRS) diff --git a/check_history.sh b/check_history.sh new file mode 100755 index 0000000000..64ea76a807 --- /dev/null +++ b/check_history.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +if [ -e .histignore ] +then + exit 0 +fi + +if [ $GITHUB_ACTION ] +then + exit 0 +fi + +has_hist=false +has_git=1 +if which git >/dev/null +then + has_hist="$(git rev-parse --is-inside-work-tree 2>/dev/null)" +else + has_git=0 +fi + +if [ $has_git -ne 1 ] +then + echo -e "\033[0;31mfatal: \033[0m\033[1;33mgit was not found. You will be unable to use version control, update pokeemerald-expansion, or use feature branches. To use version control, install \`git\` and clone the repository instead of using \"Download Zip\" on GitHub. Run \`touch .histignore\` to ignore this and continue anyways.\033[0m" + exit 1 +fi + +if [ "$has_hist" ] +then + exit 0 +else + echo -e "\033[0;31mfatal: \033[0m\033[1;33mno git history found. You will be unable to use version control, update pokeemerald-expansion, or use feature branches. To use version control, use \`git\` to clone the repository instead of using \"Download Zip\" on GitHub. Run \`touch .histignore\` to ignore this and continue anyways.\033[0m" + exit 1 +fi +