#!/bin/bash # sunrise-commit - Automates the Gentoo Sunrise Overlay commit process # Released into the public domain # $Id$ source /sbin/functions.sh BLUE=$BRACKET BOLD=$'\e[0;01m' DARKGREEN=$'\e[32m' GREEN=$GOOD LIGHTBLUE=$HILITE RED=$BAD YELLOW=$WARN commit_category="$(echo `pwd` | awk -F/ '{ print $(NF-1) }')" commit_package="$(echo `pwd` | awk -F/ '{ print $NF }')" commit_status="$(echo `svn status`)" num_new_dirs=0 opt_changelog=0 opt_noformat=0 opt_norepoman=0 opt_noupdate=0 opt_quiet=0 opt_verbose=0 changelog_append() { if [[ "$opt_changelog" == "1" ]] ; then ebegin "Appending/creating ChangeLog" echangelog "$*" eend $? fi } create_digests() { if [[ "$(ls)" =~ '\.ebuild' ]] ; then ebegin "Digesting ebuilds" for i in *.ebuild ; do ebuild $i digest done eend $? fi } repoman_check() { if [[ "$opt_norepoman" == "0" ]] ; then commit_status="$(echo `svn status`)" if [[ "$commit_status" =~ '\.ebuild' ]] ; then ebegin "Running repoman" export PORTDIR_OVERLAY="$(dirname $(dirname $(pwd)))" repoman eend $? fi fi } svn_add() { ebegin "Adding local changes to working copy" if [[ "$opt_verbose" == "1" ]] ; then svn add * --force else svn add * --force -q fi eend $? } svn_commit() { local commit_message="$*" for (( i=num_new_dirs ; i > 0 ; i-- )) ; do cd .. done if [[ "$opt_noformat" == "0" ]] ; then commit_status="$(echo `svn status`)" if [[ "$commit_status" =~ '\.ebuild' ]] ; then commit_message="${commit_category}/${commit_package}: ${commit_message}" else commit_message="${commit_package}/$(echo $commit_status | awk '{ print $2 }'): ${commit_message}" fi fi echo echo "${DARKGREEN}The following local changes will be committed to the repository:${NORMAL}" echo svn status echo echo "${DARKGREEN}The following commit message will be used:${NORMAL}" echo echo "$commit_message" if [[ "$opt_quiet" == "0" ]] ; then echo echo -n "${BOLD}Commit changes?${NORMAL} [${GREEN}Yes${NORMAL}/${RED}No${NORMAL}] " read choice echo case "$choice" in y*|Y*|"") ;; *) echo "Quitting." echo return 1 ;; esac fi ebegin "Committing working copy to repository" svn commit -m "$commit_message" eend $? } svn_up() { if [[ "$opt_noupdate" == "0" ]] ; then while [[ "$(echo `svn status`)" =~ "A.+? \." ]] ; do pushd .. >/dev/null (( num_new_dirs++ )) done ebegin "Updating working copy to latest version from repository" if [[ "$opt_verbose" == "1" ]] ; then svn update || set $? else svn update -q || set $? fi eend ${1:-0} for (( i=$num_new_dirs ; i > 0 ; i-- )) ; do popd >/dev/null done fi return ${1:-0} } usage() { cat << EOF ${BOLD}Usage:${NORMAL} ${LIGHTBLUE}sunrise-commit${NORMAL} [ ${GREEN}options${NORMAL} ] ${BLUE}message${NORMAL} ${GREEN}options${NORMAL}: ${BOLD}--changelog, -c${NORMAL} Create a ChangeLog entry using ${BLUE}message${NORMAL} ${BOLD}--help, -h${NORMAL} Show help ${BOLD}--noformat, -m${NORMAL} Disable automatic formatting of ${BLUE}message${NORMAL} ${BOLD}--norepoman, -p${NORMAL} Skip repoman check ${BOLD}--noupdate, -d${NORMAL} Don't update from repository before committing ${BOLD}--quiet, -q${NORMAL} Don't ask for confirmation ${BOLD}--verbose, -v${NORMAL} Show detailed information during commit ${BLUE}message${NORMAL}: Commit message describing changes and listing names/emails of anyone (other than the commiter) who contributed. EOF exit ${1:-0} } [[ -z "$1" ]] && usage 1 while [[ $# > 0 ]] ; do case "$1" in --changelog|-c) if [[ -z "$ECHANGELOG_USER" ]] ; then echo "!!! Error: --changelog option requires ECHANGELOG_USER to be set:" echo "!!! export ECHANGELOG_USER=\"Your Name \"" exit 1 fi opt_changelog=1 shift ;; --help|-h) usage ;; --noformat|-m) opt_noformat=1 shift ;; --norepoman|-p) opt_norepoman=1 shift ;; --noupdate|-d) opt_noupdate=1 shift ;; --quiet|-q) opt_quiet=1 shift ;; --verbose|-v) opt_verbose=1 shift ;; -*) echo "!!! Error: Unknown option ${1}. See: sunrise-commit -h" exit 1 ;; *) break ;; esac done if [[ -z "$*" ]] ; then echo "!!! Error: You must supply a commit message. See: sunrise-commit -h" exit 1 fi if [[ -z "$commit_status" ]] ; then ewarn "No changes found in current directory tree." exit 1 fi svn_up || exit $? create_digests || exit $? changelog_append "$*" || exit $? svn_add || exit $? repoman_check || exit $? svn_commit "$*" || exit $?