Skip to content

Commit

Permalink
Reformatted stuff and fixed a few typos.
Browse files Browse the repository at this point in the history
  • Loading branch information
chopmo committed Jun 22, 2012
1 parent ce38b7a commit 5493742
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 39 deletions.
14 changes: 7 additions & 7 deletions README
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
git-autopush
============

Very simple bash script to add an auto-push post commit hook in the
current Git repo. After running this script, all committed changes to
the repo will be immediately pushed to the configured remote/branch.
Very simple bash script to add an auto-push post commit hook in the current Git
repo. After running this script, all committed changes to the repo will be
immediately pushed to the configured remote/branch.


Accepts a remote repo name as parameter
if you would like to push to another repo
Accepts a remote repo name as parameter if you would like to push to another
repo.

OPTIONS:
-o will overwrite the post commit hook
-r [repo] Remote Repo to push to
-o Overwrite any existing post commit hook
-r [repo] Remote repo to push to
64 changes: 32 additions & 32 deletions git-autopush.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/bin/sh

usage()
usage()
{
cat << EOF
usage $0 [<options>] [-r <remoterepo>]
will add a post-commit function in the git repo
which will automaticly push to the default or remote repo
Will add a post-commit function in the git repo which will automatically push
to the default or remote repo.
OPTIONS:
-o Overwrite post-commit
-r Remote Repo
-o Overwrite any existing post-commit hook
-r Remote repo
EOF
}
params="$@"
Expand All @@ -19,39 +19,39 @@ OVERWRITE=0

while getopts "hor:" OPTION
do
case $OPTION in
h)
usage
exit 1
;;
o)
OVERWRITE=1
;;
r)
REMOTEREPO="$OPTARG"
;;
esac
case $OPTION in
h)
usage
exit 1
;;
o)
OVERWRITE=1
;;
r)
REMOTEREPO="$OPTARG"
;;
esac
done
shift $(( $OPTIND - 1 ))

HOOKS_FOLDER=.git/hooks
POST_COMMIT=$HOOKS_FOLDER/post-commit

if [ -d $HOOKS_FOLDER ]; then
if [ -f $POST_COMMIT ] && [ $OVERWRITE -eq 0 ]; then
echo "Post commit hook already exits, please add 'git push' manually in .git/hooks/post-commit"
exit 1
fi
if [ $OVERWRITE -eq 1 ]; then
mv $POST_COMMIT "$POST_COMMIT.bak"
echo "moved old hook to $POST_COMMIT.bak"
fi
echo "git push $REMOTEREPO" > $POST_COMMIT
chmod 755 $POST_COMMIT
REPOSITORY_BASENAME=$(basename "$PWD")
echo "added auto commit to $REPOSITORY_BASENAME"
exit 0
else
echo "This command must be run in the root of a Git repository."
if [ -f $POST_COMMIT ] && [ $OVERWRITE -eq 0 ]; then
echo "Post commit hook already exits, please add 'git push' manually in .git/hooks/post-commit"
exit 1
fi
if [ $OVERWRITE -eq 1 ]; then
mv $POST_COMMIT "$POST_COMMIT.bak"
echo "moved old hook to $POST_COMMIT.bak"
fi
echo "git push $REMOTEREPO" > $POST_COMMIT
chmod 755 $POST_COMMIT
REPOSITORY_BASENAME=$(basename "$PWD")
echo "added auto commit to $REPOSITORY_BASENAME"
exit 0
else
echo "This command must be run in the root of a Git repository."
exit 1
fi

0 comments on commit 5493742

Please sign in to comment.