#!/bin/bash # # git-sync.sh - helper app for pull/push cycle with VERSION file update # Copyright (C) 2011 Clifford Wolf # # 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. export LC_ALL=C set -e # make sure that everyone will recognize an error.. trap 'echo; echo; echo; banner " ERROR" || echo " *ERROR*"; echo; echo; exit 1' ERR if [ ! -d .git ]; then echo "You need to run this command from the toplevel of the working tree." >&2 false; exit 1 fi if [ "$(git rev-parse master)" != "$(git rev-parse HEAD)" ]; then echo "You need to run this command from the HEAD of the master branch." >&2 false; exit 1 fi git pull if [ "$(git rev-parse master)" != "$(git rev-parse origin/master)" ] then if [ -f VERSION ]; then if ! egrep -q '\.[0-9]+$' VERSION || [ `wc -l < VERSION` -ne 1 ]; then echo "Invalid syntax in VERSION file!" >&2 false; exit 1 fi gawk 'BEGIN { FS="."; OFS="."; } { $NF++; print $0; }' < VERSION > .VERSION.tmp echo "Updated version file: `cat VERSION` -> `cat .VERSION.tmp`" mv .VERSION.tmp VERSION git commit -C HEAD --amend VERSION fi git push fi echo "READY."