Created
March 2, 2014 08:44
-
-
Save mcbrwr/9303757 to your computer and use it in GitHub Desktop.
AutoGit. Monitor a working copy and add/commit/pull/push on file changes. Nice for staging servers, not for production ofcourse..
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
sha=0 | |
previous_sha=0 | |
commitmsg="online changes (autogit)" | |
if [ $1 ]; then | |
repo=$1 | |
else | |
repo='.' | |
fi | |
echo "--> sanity checking repo: $repo" | |
# check if repo exists | |
# todo: do something like "git status | grep fatal" | |
if [ ! -d "$repo/.git" ]; then | |
echo "FATAL. Directory $1 does not exist or is not a git repo." | |
exit 0 | |
fi | |
echo "--> Repo sane. Monitoring." | |
cd $repo | |
update_sha() { | |
sha=`ls -laR $repo | sha1sum` | |
} | |
go () { | |
git add . | |
git commit -am "$commitmsg" | |
git pull | |
git push | |
echo | |
echo "--> Monitor: Monitoring working copy... (Press enter to force commit)" | |
} | |
changed () { | |
echo "--> Files changed, committing..." | |
go | |
previous_sha=$sha | |
} | |
compare () { | |
update_sha | |
if [[ $sha != $previous_sha ]] ; then changed; fi | |
} | |
run () { | |
echo "--> Monitor: Monitoring filesystem... (Press enter to force commit)" | |
while true; do | |
compare | |
read -s -t 1 && ( | |
echo "--> Monitor: Forced Update..." | |
go | |
) | |
done | |
} | |
echo "--> Autogit: Init..." | |
run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
todo: error checking in git actions (merge conflict MIGHT be nice to handle..)