#!/bin/bash # $Id: $ source /sbin/functions.sh BOLD=$'\e[0;01m' GREEN=$'\e[32m' changelog=0 force=0 noupdate=0 quiet=0 verbose=0 changelog_append() { if [[ "$changelog" == "1" ]] ; then ebegin "Appending/creating ChangeLog" echangelog "$1" eend $? else return 0 fi } create_digests() { ebegin "Digesting ebuilds" for i in *.ebuild ; do ebuild $i digest done eend $? } svn_add() { ebegin "Adding local changes to working copy" if [[ "$verbose" == "1" ]] ; then svn add * else svn add -q * fi eend $? } svn_commit() { ebegin "Committing working copy to repository" svn commit -m "$*" eend $? } svn_up() { if [[ "$noupdate" == "0" ]] ; then ebegin "Updating working copy to latest version from repository" if [[ "$verbose" == "1" ]] ; then svn update else svn update -q fi eend $? else return 0 fi } usage() { cat << EOF ${BOLD}Usage:${NORMAL} ${HILITE}sunrise-commit${NORMAL} [ ${GOOD}option${NORMAL} ] ${GOOD}message${NORMAL} ${GOOD}option${NORMAL} is: ${BOLD}-c, --changelog${NORMAL} Also create a ChangeLog entry using ${GOOD}message${NORMAL} ${BOLD}-f, --force${NORMAL} Commit even if no ebuilds are present ${BOLD}-h, --help${NORMAL} Show help ${BOLD}-n, --noupdate${NORMAL} Don't update from repository before committing ${BOLD}-q, --quiet${NORMAL} Don't ask for confirmation ${BOLD}-v, --verbose${NORMAL} Show more detailed information during commit ${GOOD}message${NORMAL} is: Message describing commit. For new ebuilds the suggested message format is: "New Ebuild for bug ${BRACKET}Gentoo bug #${NORMAL}, thanks to ${BRACKET}list of contributors${NORMAL}" EOF exit ${1:-0} } [[ -z "$1" ]] && usage 1 if [[ -z "$(echo `svn status`)" ]] ; then ewarn "No changes found in current directory." exit 1 fi 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 changelog=1 shift ;; --force|-f) force=1 shift ;; --help|-h) usage ;; --noupdate|-n) noupdate=1 shift ;; --quiet|-q) quiet=1 shift ;; --verbose|-v) verbose=1 shift ;; *) break ;; esac done if [[ -z "$*" ]] ; then echo "!!! Error: You must supply a commit message. See: sunrise-commit -h" exit 1 fi svn_up || exit $? if [[ "$force" == "0" ]] ; then if [[ ! $(find *.ebuild -maxdepth 0) ]] ; then echo "!!! Error: No ebuilds found in current directory. Use -f to force commit." exit 1 fi create_digests || exit $? fi changelog_append "$1" || exit $? svn_add || exit $? if [[ "$verbose" == "1" ]] ; then echo echo "${GREEN}The following local changes will be committed to the repository:${NORMAL}" echo svn status fi if [[ "$quiet" == "0" ]] ; then echo echo -n "${BOLD}Commit changes?${NORMAL} [${GOOD}Yes${NORMAL}/${BAD}No${NORMAL}] " read choice echo case "$choice" in y*|Y*|"") ;; *) echo "Quitting." echo exit 1 ;; esac fi svn_commit "$*" || exit $?