First commit

This commit is contained in:
Jack-Benny Persson 2013-06-08 02:50:39 +02:00
commit 01066378af
2 changed files with 136 additions and 0 deletions

22
README.md Normal file
View File

@ -0,0 +1,22 @@
autogitit
=========
autogitit is a small Bash script I wrote to automatically commit changes in a spcified direcory to git. Each time the script runs it checks if there is something new to commit or not. If the directory is clean the script will simply quit and do nothing.
The usage for it could be both as a kind of directory snapshot but also for your regular git repos so you don't forget to commit any changes. The downside if you use it your for regular git repos is that the commit messages will be marked with "autogitit on YYYY-MM-DD HH:MM:SS" and it won't push to remotes (as of right now anyway).
How to use it
-------------
First of all change the variable GITDIR in autogitit.sh to point to the directory that you want to auto commit to. It's between the START CONFIG and END CONFIG comments.
Next add an entry for autogitit.sh in your crontab, for example to run every five minutes. Below is an example of how to do it and what how the line will look like.
$ crontab -e
*/10 * * * * /home/user/autogitit.sh
If you want to initalize a directory for use with autogitit you can either do this by your self with a "git init" or by running the script with the --init option.
Contributing
------------
Any contributions are welcome since this is only half done, althouh it's working and should run out of the box on most Unix-like systems.
Add yourself to the THANKS file if you like to after contributing to the project.

114
autogitit.sh Executable file
View File

@ -0,0 +1,114 @@
#!/bin/bash
################################################################################
# #
# Copyright (C) 2013 Jack-Benny Persson <jack-benny@cyberinfo.se> #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the Free Software #
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #
# #
################################################################################
###############################################################################
# #
# autogitit #
# A simple shell script to automatically commit a directory to git. #
# I myself use it as a kind of directory snapshot. I got the idea with #
# directory snapshots while playing with Solaris 11. I wanted something #
# similar but more universal without a specific filesystem and something #
# that used commons tools, and Git was the obvious choice. #
# #
###############################################################################
VERSION="Version 0.1"
AUTHOR="(c) 2013 Jack-Benny Persson (jack-benny@cyberinfo.se)"
## BEGIN SETTINGS ##
## Set this to the directory to auto commit ##
GITDIR="/home/jackbenny/gittest"
## END SETTINGS ##
## Other variables ##
WHICH="/usr/bin/which"
GIT="`${WHICH} git`"
DATE="`${WHICH} date`"
## Sanity checks ##
if [ ! -x $GIT ]; then
printf "It seems you don't have git installed.\n"
printf "Check the GIT variable in autogitit if your sure it's "
printf "installed.\n"
exit 1
fi
if [ ! -f $CONFIG ]; then
printf "Can't find config file at $CONFIG\n"
exit 1
fi
## Script begins here ##
TIMESTAMP=`${DATE} --rfc-3339=seconds`
## Define some functions ##
init()
{
test -d $GITDIR/.git
if [ $? -ne 0 ]; then
printf "Initlizing $GITDIR\n"
cd $GITDIR
git init
main
exit 0
else
printf "It seems that $GITDIR is already a initalized"
printf ". Continuing....\n"
printf "Remove --init from commandline to silence this"
printf " message\n"
exit 1
fi
}
main()
{
cd $GITDIR
git status | grep "nothing to commit" > /dev/null
if [ $? -eq 0 ]; then
exit 0
else
git add -A
git commit -m "autogitit on $TIMESTAMP" > /dev/null
fi
}
## Here we go ##
while [[ -n "$1" ]]; do
case "$1" in
--init)
init
;;
esac
done
test -d $GITDIR/.git
if [[ $? -ne 0 ]]; then
printf "$GITDIR is not initalized as a git dir.\n"
printf "Use --init to initalize.\n"
else
main
fi