From 0e11c2e0fba408d24f53076c02ff7270b9c2a9b4 Mon Sep 17 00:00:00 2001 From: tracer-ysyx Date: Fri, 5 Jan 2024 00:07:40 +0800 Subject: [PATCH] =?UTF-8?q?>=20git=5Fcommit.sh=20=20ysyx=5F22040000=20?= =?UTF-8?q?=E6=9D=8E=E5=BF=83=E6=9D=A8=20=20Linux=20calcite=206.1.69=20#1-?= =?UTF-8?q?NixOS=20SMP=20PREEMPT=5FDYNAMIC=20Wed=20Dec=2020=2016:00:29=20U?= =?UTF-8?q?TC=202023=20x86=5F64=20GNU/Linux=20=20=2000:07:40=20=20up=20=20?= =?UTF-8?q?=208:54,=20=202=20users,=20=20load=20average:=200.53,=200.45,?= =?UTF-8?q?=200.39?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git_commit.sh | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 git_commit.sh diff --git a/git_commit.sh b/git_commit.sh new file mode 100755 index 0000000..460cfcf --- /dev/null +++ b/git_commit.sh @@ -0,0 +1,55 @@ +#/usr/bin/env bash +# +# Environment Variables: +# NEMU_HOME +set -x + +STUID=ysyx_22040000 +STUNAME=李心杨 + +TRACER=tracer-ysyx +GITFLAGS="-q --author=$TRACER --no-verify --allow-empty" + +YSYX_HOME=$NEMU_HOME/.. +WORK_BRANCH=$(git rev-parse --abbrev-ref HEAD) +WORK_INDEX=$YSYX_HOME/.git/index.${WORK_BRANCH} +TRACER_BRANCH=$TRACER + +LOCK_DIR=$YSYX_HOME/.git/ + +git_soft_checkout () { + git checkout --detach -q && git reset --soft $1 -q -- && git checkout $1 -q -- ; +} + +git_commit () { + # create tracer branch if not existent + git branch $TRACER_BRANCH -q 2>/dev/null || true + # backup git index + cp -a .git/index $WORK_INDEX + # switch to tracer branch + git_soft_checkout "$TRACER_BRANCH" + # add files to commit + git add . -A --ignore-errors + # generate commit msg, commit changes in tracer branch + printf "> $1 \n $STUID $STUNAME \n $(uname -a) \n $(uptime)\n" | git commit -F - $GITFLAGS + git_soft_checkout "$WORK_BRANCH" + mv $WORK_INDEX .git/index +} + +git_commit $1 + +# TIMEOUT=2 +# LOCKFILE=$YSYX_HOME/.git/index.lock +# exec {FD}<>$LOCKFILE + +# if ! flock -x -w $TIMEOUT $FD; then +# echo "Failed to obtain a lock within $TIMEOUT seconds" +# echo "Another instance of `basename $0` is probably running." +# exit 1 +# else +# echo "Lock acquired" +# git_commit $1 +# rm -f $WORK_INDEX +# exit 0 +# fi +