From 9f1235ec873fee9dfb7cec264ea2186e316bc0e0 Mon Sep 17 00:00:00 2001 From: shmick Date: Mon, 10 May 2021 18:18:28 +0300 Subject: [PATCH] Imported Git auto-commit scripts from work with mild changes --- GitDaemon | 11 +++++++++++ GitUpstreamer | 17 +++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100755 GitDaemon create mode 100755 GitUpstreamer diff --git a/GitDaemon b/GitDaemon new file mode 100755 index 0000000..a2e5fbf --- /dev/null +++ b/GitDaemon @@ -0,0 +1,11 @@ +#small script to be appended to bash.profile; calls the GitUpstreamer script to auto-commit changes +function cd { +# Actually change the directory with all args passed to the function +if builtin cd "$@"; then + # If the dir exists, run the git script on git directories + if [[ -d ".git" ]] ; then + echo "[git]: Note $(pwd) is under Git revision control." + . "$SCRIPTS/GitUpstreamer" + fi +fi + } diff --git a/GitUpstreamer b/GitUpstreamer new file mode 100755 index 0000000..26a16fc --- /dev/null +++ b/GitUpstreamer @@ -0,0 +1,17 @@ +#!/bin/bash +#Scripts to detect and push changes if exist; Runs in Git direcories, called by GitDaemon script. +source ~/.bash_profile > /dev/null +source ~/.zshrc > /dev/null +#Exclude directories with the .noautocommit file; +if [[ -f .autocommit ]]; then + if [[ -z $(git status | grep "nothing") ]]; then + #If working state is not clean - assume dirty directory + echo "[git]: Directory $(pwd) has changes uncommited to git. Adding changes..." + git add . -A #Adds only essentials via reverse gitignore + echo "[git]: Committing changes..." + git commit -m "Scripted commit - $(date)" + git push >/dev/null 2>&1 + elif [[ -n $(git status | grep "nothing") ]]; then + echo "[git]: Directory has no uncommited changes." > /dev/null + fi +fi