From ed7dcb7682c7bfded308a98d48fd8f9f72df30ca Mon Sep 17 00:00:00 2001 From: Andrew Janke Date: Fri, 2 Oct 2015 05:47:08 -0400 Subject: [PATCH] Makefile: refactor is-git-repo inclusion logic This avoids the need for a big repeated block of code. --- Makefile | 26 ++++++++------------------ need_git_repo | 6 ++++++ 2 files changed, 14 insertions(+), 18 deletions(-) create mode 100644 need_git_repo diff --git a/Makefile b/Makefile index a2f5caa..a68ab18 100644 --- a/Makefile +++ b/Makefile @@ -5,11 +5,10 @@ BINS = $(wildcard bin/git-*) MANS = $(wildcard man/git-*.md) MAN_HTML = $(MANS:.md=.html) MAN_PAGES = $(MANS:.md=.1) +# Libraries used by all commands LIB = "helper/reset-env" "helper/git-extra-utility" -COMMANDS_USED_WITHOUT_GIT_REPO = git-alias git-extras git-fork git-setup -COMMANDS_USED_WITH_GIT_REPO = $(filter-out $(COMMANDS_USED_WITHOUT_GIT_REPO), \ - $(subst bin/, , $(BINS))) +COMMANDS = $(subst bin/, , $(BINS)) default: install @@ -25,7 +24,7 @@ install: @chmod 775 $(TEMPFILE) $(eval EXISTED_ALIASES := $(shell \ git config --get-regexp 'alias.*' | awk '{print "git-" substr($$1, 7)}')) - @$(foreach COMMAND, $(COMMANDS_USED_WITH_GIT_REPO), \ + @$(foreach COMMAND, $(COMMANDS), \ disable=''; \ if test ! -z "$(filter $(COMMAND), $(EXISTED_ALIASES))"; then \ read -p "$(COMMAND) conflicts with an alias, still install it and disable the alias? [y/n]" answer; \ @@ -33,20 +32,11 @@ install: fi; \ if test -z "$$disable"; then \ echo "... installing $(COMMAND)"; \ - head -1 bin/$(COMMAND) | cat - $(LIB) ./helper/is-git-repo > $(TEMPFILE); \ - tail -n +2 bin/$(COMMAND) >> $(TEMPFILE); \ - cp -f $(TEMPFILE) $(DESTDIR)$(BINPREFIX)/$(COMMAND); \ - fi; \ - ) - @$(foreach COMMAND, $(COMMANDS_USED_WITHOUT_GIT_REPO), \ - disable=''; \ - if test ! -z "$(filter $(COMMAND), $(EXISTED_ALIASES))"; then \ - read -p "$(COMMAND) conflicts with an alias, still install it and disable the alias? [y/n]" answer; \ - test "$$answer" = 'n' -o "$$answer" = 'N' && disable="true"; \ - fi; \ - if test -z "$$disable"; then \ - echo "... installing $(COMMAND)"; \ - head -1 bin/$(COMMAND) | cat - $(LIB) > $(TEMPFILE); \ + head -1 bin/$(COMMAND) > $(TEMPFILE); \ + cat $(LIB) >> $(TEMPFILE); \ + if grep "$(COMMAND)" need_git_repo >/dev/null; then \ + cat ./helper/is-git-repo >> $(TEMPFILE); \ + fi; \ tail -n +2 bin/$(COMMAND) >> $(TEMPFILE); \ cp -f $(TEMPFILE) $(DESTDIR)$(BINPREFIX)/$(COMMAND); \ fi; \ diff --git a/need_git_repo b/need_git_repo new file mode 100644 index 0000000..5f5e388 --- /dev/null +++ b/need_git_repo @@ -0,0 +1,6 @@ +# A list of the commands that use is_git_repo, and should have +# it included in the "built" version of the command +git-alias +git-extras +git-fork +git-setup