From a28bbd7a3b23870aa6228a5b978a5b305eefcf61 Mon Sep 17 00:00:00 2001 From: huaixv <44743118+huaixv@users.noreply.github.com> Date: Fri, 25 Feb 2022 17:45:35 +0800 Subject: [PATCH] feat: add shadow branch for tracer --- Makefile | 18 +++++++++++++++--- init.sh | 8 ++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index e4cbbd8..0effd09 100644 --- a/Makefile +++ b/Makefile @@ -5,11 +5,23 @@ STUNAME = 张三 GITFLAGS = -q --author='tracer-ysyx2204 ' --no-verify --allow-empty +WORK_BRANCH = $(shell git rev-parse --abbrev-ref HEAD) +TRACER_BRANCH = ysyx-tracer + # prototype: git_commit(msg) define git_commit - -@git add .. -A --ignore-errors - -@while (test -e .git/index.lock); do sleep 0.1; done - -@(echo "> $(1)" && echo $(STUID) $(STUNAME) && uname -a && uptime) | git commit -F - $(GITFLAGS) + -@cd $(YSYX_HOME) && while (test -e .git/index.lock); do sleep 0.1; done; `# wait for other git instances` + -@cd $(YSYX_HOME) && git branch $(TRACER_BRANCH) -q 2>/dev/null || true `# create tracer branch if not existent` + -@cd $(YSYX_HOME) && git worktree add $(TRACER_BRANCH) -q `# check out tracer branch` + -@cd $(YSYX_HOME) && git status --untracked-files -z `# list changed files to copy (w/o quotes)` \ + | tr '\000' '\n' `# restore EOL sequence` \ + | cut -c 1-3 --complement `# remove status indicator` \ + | grep -v '^$(TRACER_BRANCH)/' `# skip tracer worktree` \ + | rsync -aq --files-from=- ./ $(TRACER_BRANCH)/ `# call rsync to copy files` + -@cd $(YSYX_HOME) && git -C $(TRACER_BRANCH) add . -A --ignore-errors `# add changes to staging area` + -@cd $(YSYX_HOME) && (echo "> $(1)" && echo $(STUID) $(STUNAME) && uname -a && uptime `# generate commit msg`) \ + | git -C $(TRACER_BRANCH) commit -F - $(GITFLAGS) `# commit changes in tracer branch` + -@cd $(YSYX_HOME) && git worktree remove $(TRACER_BRANCH) -f `# remove tracer worktree` -@sync endef diff --git a/init.sh b/init.sh index 5a7a3ff..3b44360 100644 --- a/init.sh +++ b/init.sh @@ -66,6 +66,14 @@ case $1 in sed -i -e "/^export NPC_HOME=.*/d" ~/.bashrc echo "export NPC_HOME=`readlink -e npc`" >> ~/.bashrc + echo "By default this script will add environment variables into ~/.bashrc." + echo "After that, please run 'source ~/.bashrc' to let these variables take effect." + echo "If you use shell other than bash, please add these environment variables manually." + ;; + ysyx) + sed -i -e "/^export YSYX_HOME=.*/d" ~/.bashrc + echo "export YSYX_HOME=`readlink -e .`" >> ~/.bashrc + echo "By default this script will add environment variables into ~/.bashrc." echo "After that, please run 'source ~/.bashrc' to let these variables take effect." echo "If you use shell other than bash, please add these environment variables manually."