From a15315093eb14643e5773534040654c552eb1fa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Mon, 12 Jul 2010 00:16:24 +0200 Subject: [PATCH] Introduce new sunrise-commit implementation. It is basically a nice frontend to call 'echangelog' and 'repoman commit'. The current code supports git only, and works only inside the package directory. Additionally, it requires new enough repoman (which means live portage version right now). --- sunrise-commit | 141 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100755 sunrise-commit diff --git a/sunrise-commit b/sunrise-commit new file mode 100755 index 0000000..7dd596b --- /dev/null +++ b/sunrise-commit @@ -0,0 +1,141 @@ +#!/bin/sh +# sunrise-commit -- a helper script for Sunrise commiters. +# (c) 2010 Michał Górny +# Released under the terms of the 3-clause BSD license. + +# Few output helpers. +die() { + echo "${@}" >&2 + exit 1 +} + +sayv() { + [ -n "${SC_VERBOSE}" ] && echo "${@}" >&2 +} + +req() { + "$@" || die "$@ failed." +} + +# POSIX compat. +local_supported() { + local test 2>/dev/null +} + +local_supported || eval 'local() { + unset ${@} +}' + +# See if we're in a repo, and what VCS are we using. +find_repo() { + svn info >/dev/null 2>&1 + + if [ ${?} -eq 0 ]; then + SC_VCS=svn + else + local remotes + remotes=$(git branch -r 2>/dev/null) + + if [ ${?} -ne 127 -a ${?} -ne 128 ]; then + echo "${remotes}" | grep git-svn >/dev/null 2>&1 + if [ ${?} -eq 0 ]; then + SC_VCS=git-svn + else + SC_VCS=git + fi + else + die 'Unable to find any familiar repository type (are you inside the repo?).' + fi + fi + + if [ ${SC_VCS} = svn ]; then + die 'Native subversion repositories are not supported at the moment.' + fi + + sayv "Ok, we're in ${SC_VCS} working tree. Let's see what I can do around here..." +} + +# Look around for ebuilds. +find_ebuilds() { + # POSIX is fun -- look for ebuilds in the current directory. + if [ -n "$(find \( -name '*.ebuild' -print -o ! -name '.' -prune \))" ]; then + local stripped + + # Get CATEGORY and PN. + stripped=${PWD%/*} + stripped=${stripped%/*} + SC_CP=${PWD#${stripped}/} + + SC_SCENARIO=ebuild-commit + sayv "We have some ebuilds for ${SC_CP} here." + else + die 'No familar situation found -- no ebuilds here.' + fi +} + +# VCS helpers. +check_for_changes() { + local output + + if [ ${SC_VCS%-svn} = git ]; then + output="$(git diff-index --name-status --relative HEAD)" + fi + + sayv "${output}" + [ -n "${output}" ] +} + +vcs_reset() { + if [ ${SC_VCS%-svn} = git ]; then + req git reset -q HEAD "${1}" + req git checkout -f "${1}" + fi +} + +# Guess what! +main() { + local commitmsg + unset SC_VERBOSE + + while [ ${#} -gt 0 ]; do + case "${1}" in + -v|--verbose) + SC_VERBOSE=1 + ;; + --) + shift + commitmsg="${commitmsg+${commitmsg} }${@}" + break + ;; + *) + commitmsg="${commitmsg+${commitmsg} }${1}" + ;; + esac + shift + done + + [ -n "${commitmsg}" ] || die 'No commit message provided.' + + find_repo + find_ebuilds + + case ${SC_SCENARIO} in + ebuild-commit) + check_for_changes || die 'No changes found to commit.' + + # With native git repos, we do not do ChangeLogs by default... + # ...at least unless they're already there. + if [ ${SC_VCS} = git -a ! -f ChangeLog ]; then + sayv 'Cleaning up the ChangeLog...' + vcs_reset ChangeLog + sayv '...and appending to it.' + echangelog "${commitmsg}" + fi + + sayv "Now, let's let repoman do its job..." + exec repoman commit -a -m "${SC_CP}: ${commitmsg}" + ;; + esac +} + +main "${@}"