From 1d169e7eb5eb75e3b15bea73fdfdbc8444902d84 Mon Sep 17 00:00:00 2001 From: alibaba Date: Thu, 21 Apr 2022 12:49:47 +0000 Subject: [PATCH] Add 'git_auto_save.sh' --- git_auto_save.sh | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 git_auto_save.sh diff --git a/git_auto_save.sh b/git_auto_save.sh new file mode 100644 index 0000000..1e52ba2 --- /dev/null +++ b/git_auto_save.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +echo 'Auto Syncing' + +while true +do + # check every 30s + sleep 30 + + # sync only 5min after last modifiication to avoid too many temperaty updates + last_modified=`find ./ -type f -exec stat \{} --printf="%Y\n" \; | sort -n -r | head -n 1` + current=`date +%s` + if (( ${current} - ${last_modified} < 300 )); then + continue + fi + + # commit changes -> pull rebase -> push to remote + no_output=`git diff-index --quiet HEAD --` + is_dirty=$? + + if [ -n "$(git status --porcelain)" ]; then + is_dirty=1 + fi + + if test "$is_dirty" = 0; then + continue + fi + + git add . -A + git commit -am "Auto update by $(whoami)" + git pull --rebase + git push origin master + +done \ No newline at end of file