💾 SuperFloppies Place! 💾

git Mirrors with GNU Make

I have a directory that has git repositories, plus subdirectories with more git repositories. Here is the GNU makefile I use to keep it up to date.

all: ;

DATE    := $(shell date +"%Y%m%d")
SUBDIRS := operating-systems mate
DIRS := $(filter-out GNUmakefile $(SUBDIRS),$(wildcard *))

define ADD_TO_LIST
$(1) += $(wildcard $(2)/*)
endef

$(foreach d,$(SUBDIRS),$(eval $(call ADD_TO_LIST,DIRS,$(d))))

.update.$(DATE).stamp: GNUmakefile $(DIRS)
	@find . -maxdepth 1 -mtime +1 -name '.update.*.stamp' | xargs rm -f
	@for i in $(DIRS); do ( cd $$i; printf "\n\n **** UPDATING %s ****\n\n" "$$i"; git pull ); done
	@touch $@

update: .update.$(DATE).stamp

all: update

This will only update the mirrors once per day, unless the makefile or any of the directories is newer than the stamp file. It also cleans up old stamp files so that it doesn’t litter the directory. You can run make a hundred times in an hour, and it will only update the repositories once.

If you want to force an update, just touch GNUmakefile && make and there you go.

You have to:

Alternative with Terminal Title Support

This version supports showing the current update being processed in the terminal title, so that it is visible on the task list where the terminal window is being displayed.

all: ;

DATE    := $(shell date +"%Y%m%d")
SUBDIRS := operating-systems mate
DIRS := $(filter-out GNUmakefile $(SUBDIRS),$(wildcard *))

define ADD_TO_LIST
$(1) += $(wildcard $(2)/*)
endef

$(foreach d,$(SUBDIRS),$(eval $(call ADD_TO_LIST,DIRS,$(d))))

.update.$(DATE).stamp: GNUmakefile $(DIRS)
	@find . -maxdepth 1 -mtime +1 -name '.update.*.stamp' | xargs rm -f
	@for i in $(DIRS); do ( cd $$i; printf "\x1b]0;%s [U]\x07\n\n **** UPDATING %s ****\n\n" "$$i" "$$i"; git pull ); done
	@touch $@

update: .update.$(DATE).stamp

all: update

The terminal title update should work on xterm and compatible terminal emulators.