2010-07-12 00:16:24 +02:00
|
|
|
#!/bin/sh
|
2010-08-25 23:54:12 +02:00
|
|
|
# sunrise-commit -- a Gentoo repository commit helper
|
2010-07-12 00:16:24 +02:00
|
|
|
# (c) 2010 Michał Górny <gentoo@mgorny.alt.pl>
|
|
|
|
# Released under the terms of the 3-clause BSD license.
|
|
|
|
|
2010-07-13 17:15:51 +02:00
|
|
|
# -- output helpers --
|
|
|
|
|
|
|
|
# Output the message to STDERR.
|
2010-07-12 10:20:31 +02:00
|
|
|
say() {
|
2010-07-12 00:16:24 +02:00
|
|
|
echo "${@}" >&2
|
2010-07-12 10:20:31 +02:00
|
|
|
}
|
|
|
|
|
2010-07-13 17:15:51 +02:00
|
|
|
# Output the error message and abort the script with non-zero status.
|
2010-07-12 10:20:31 +02:00
|
|
|
die() {
|
2010-07-12 11:27:40 +02:00
|
|
|
say "${RED}${@}${RESET}"
|
2010-07-12 00:16:24 +02:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2010-07-13 17:15:51 +02:00
|
|
|
# Output the debug message if --verbose was used.
|
2010-07-12 00:16:24 +02:00
|
|
|
sayv() {
|
2010-07-12 11:27:40 +02:00
|
|
|
[ -n "${SC_VERBOSE}" ] && say "${GREEN}${@}${RESET}"
|
2010-07-12 00:16:24 +02:00
|
|
|
}
|
|
|
|
|
2010-07-13 17:15:51 +02:00
|
|
|
# Execute the command and die with simple error message if it fails.
|
2010-07-12 00:16:24 +02:00
|
|
|
req() {
|
2010-07-13 17:34:42 +02:00
|
|
|
"${@}" || die "'${@}' failed."
|
2010-07-12 00:16:24 +02:00
|
|
|
}
|
|
|
|
|
2010-10-02 18:35:12 +02:00
|
|
|
# Append the arguments to an IFS-separated list variable whose name was
|
|
|
|
# passed as the first arg.
|
|
|
|
array_append() {
|
|
|
|
local varname
|
|
|
|
varname=${1}
|
|
|
|
shift
|
|
|
|
|
|
|
|
eval "set -- \${${varname}} \"\${@}\"; ${varname}=\${*}"
|
|
|
|
}
|
|
|
|
|
2010-07-13 17:15:51 +02:00
|
|
|
# -- POSIX compat --
|
|
|
|
|
|
|
|
# Check whether 'local' is supported.
|
2010-07-12 00:16:24 +02:00
|
|
|
local_supported() {
|
2010-07-13 17:15:51 +02:00
|
|
|
PATH= local test 2>/dev/null
|
2010-07-12 00:16:24 +02:00
|
|
|
}
|
|
|
|
|
2010-07-13 17:15:51 +02:00
|
|
|
# If it is not, declare dummy local() function unsetting the variables.
|
2010-07-12 00:16:24 +02:00
|
|
|
local_supported || eval 'local() {
|
2010-07-13 17:15:51 +02:00
|
|
|
unset "${@}"
|
2010-07-12 00:16:24 +02:00
|
|
|
}'
|
|
|
|
|
2010-07-13 17:15:51 +02:00
|
|
|
# -- 'look around' functions --
|
|
|
|
|
2010-07-12 00:16:24 +02:00
|
|
|
# See if we're in a repo, and what VCS are we using.
|
|
|
|
find_repo() {
|
2010-08-26 00:08:21 +02:00
|
|
|
if svn info >/dev/null 2>&1; then
|
2010-07-12 00:16:24 +02:00
|
|
|
SC_VCS=svn
|
2010-08-26 18:54:14 +02:00
|
|
|
elif hg tip >/dev/null 2>&1; then
|
2010-08-24 22:33:16 +02:00
|
|
|
SC_VCS=hg
|
2010-10-27 22:22:46 +02:00
|
|
|
elif cvs status -l >/dev/null 2>&1; then
|
|
|
|
SC_VCS=cvs
|
2010-07-12 00:16:24 +02:00
|
|
|
else
|
|
|
|
local remotes
|
|
|
|
remotes=$(git branch -r 2>/dev/null)
|
|
|
|
|
|
|
|
if [ ${?} -ne 127 -a ${?} -ne 128 ]; then
|
2010-08-26 00:08:21 +02:00
|
|
|
if echo "${remotes}" | grep git-svn >/dev/null 2>&1; then
|
2010-07-12 00:16:24 +02:00
|
|
|
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
|
|
|
|
|
2010-07-12 18:18:42 +02:00
|
|
|
sayv "Ok, we're in the ${SC_VCS} working tree. Let's see what I can do around here..."
|
2010-07-12 14:59:56 +02:00
|
|
|
}
|
|
|
|
|
2010-07-13 17:15:51 +02:00
|
|
|
# Check whether a particular directory has been completely removed
|
|
|
|
# from the repo.
|
2010-07-12 14:59:56 +02:00
|
|
|
is_whole_dir_removed() {
|
2010-07-12 00:16:24 +02:00
|
|
|
if [ ${SC_VCS} = svn ]; then
|
2010-09-28 18:44:52 +02:00
|
|
|
[ "$(svn status --depth=empty -- "${1}" | wc -l)" = 1 ]
|
2010-07-12 14:59:56 +02:00
|
|
|
elif [ ${SC_VCS%-svn} = git ]; then
|
2010-07-13 17:26:36 +02:00
|
|
|
[ -z "$(git ls-files -c -- "${1}")" ]
|
2010-08-24 22:33:16 +02:00
|
|
|
elif [ ${SC_VCS} = hg ]; then
|
|
|
|
[ -z "$(hg status -madc "${1}")" ]
|
2010-10-27 22:22:46 +02:00
|
|
|
elif [ ${SC_VCS} = cvs ]; then
|
|
|
|
[ -z "$(cvs -Q status -R "${1}" 2>/dev/null | grep -e '^File:' | grep -v -e 'Status: Locally Removed$')" ]
|
2010-07-12 00:16:24 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2010-07-12 13:27:39 +02:00
|
|
|
# Check whether we're having a clean package removal.
|
|
|
|
is_package_removal() {
|
|
|
|
local fields list
|
|
|
|
[ -d profiles ] && fields=1-2 || fields=1
|
|
|
|
|
|
|
|
if [ ${SC_VCS%-svn} = git ]; then
|
2010-07-12 14:59:56 +02:00
|
|
|
list=$(git diff-index --relative --name-only --diff-filter=D HEAD)
|
2010-08-24 22:33:16 +02:00
|
|
|
elif [ ${SC_VCS} = hg ]; then
|
|
|
|
list=$(hg status -nr .)
|
2010-10-27 22:22:46 +02:00
|
|
|
elif [ ${SC_VCS} = cvs ]; then
|
|
|
|
list=$(cvs -n -q up 2>/dev/null | sed -n -e 's/^R//p')
|
2010-07-12 14:59:56 +02:00
|
|
|
elif [ ${SC_VCS} = svn ]; then
|
|
|
|
list=$(svn status -q | sed -n -e 's/^D //p')
|
2010-07-12 13:27:39 +02:00
|
|
|
fi
|
2010-07-12 14:59:56 +02:00
|
|
|
list=$(echo "${list}" | cut -d / -f ${fields} | sort | uniq)
|
2010-07-12 13:27:39 +02:00
|
|
|
|
|
|
|
# 1) We have to have any removes.
|
|
|
|
[ -z "${list}" ] && return 1
|
|
|
|
|
|
|
|
# Few more checks.
|
|
|
|
local dir olist
|
|
|
|
for dir in ${list}; do
|
|
|
|
# 2) These removes have to remove whole directories.
|
2010-10-02 18:35:12 +02:00
|
|
|
is_whole_dir_removed ${dir} && array_append olist "${dir}"
|
2010-07-12 13:27:39 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
[ -z "${olist}" ] && return 1
|
|
|
|
|
|
|
|
SC_CHANGE_LIST=${olist}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2010-07-13 17:15:51 +02:00
|
|
|
# Look around for ebuilds; determine the scenario we're working on.
|
2010-07-12 00:16:24 +02:00
|
|
|
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
|
2010-07-12 18:18:42 +02:00
|
|
|
sayv "We found ebuilds for ${SC_CP} here."
|
2010-07-12 13:27:39 +02:00
|
|
|
elif is_package_removal; then
|
|
|
|
local cplist category pkg rootprefix
|
|
|
|
# We can either have the category on the list or in PWD.
|
|
|
|
if [ -d profiles ]; then
|
|
|
|
category=
|
|
|
|
else
|
|
|
|
local stripped
|
|
|
|
stripped=${PWD%/*}
|
|
|
|
category=${PWD#${stripped}/}/
|
|
|
|
fi
|
|
|
|
|
|
|
|
SC_CP=
|
2010-08-12 22:38:18 +02:00
|
|
|
SC_REMOVED_PACKAGE_LIST=
|
2010-07-12 13:27:39 +02:00
|
|
|
# Now we can have multiple packages around.
|
|
|
|
for pkg in ${SC_CHANGE_LIST}; do
|
|
|
|
if [ -z "${category}" ]; then
|
|
|
|
case ${pkg} in
|
|
|
|
eclass/*|licenses/*|local/*|profiles/*|scripts/*)
|
|
|
|
continue
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
SC_CP=${SC_CP:+${SC_CP}, }${category}${pkg}
|
2010-10-02 18:35:12 +02:00
|
|
|
array_append SC_REMOVED_PACKAGE_LIST "${category}${pkg}"
|
2010-07-12 13:27:39 +02:00
|
|
|
done
|
|
|
|
|
2010-09-24 01:07:44 +02:00
|
|
|
SC_ROOT=${category:+../}
|
|
|
|
|
|
|
|
# Replace with the filtered version, placing all atoms
|
2010-09-26 10:37:29 +02:00
|
|
|
# relative to SC_ROOT.
|
2010-09-20 16:52:03 +02:00
|
|
|
SC_CHANGE_LIST=
|
2010-09-24 01:07:44 +02:00
|
|
|
for pkg in ${SC_REMOVED_PACKAGE_LIST}; do
|
2010-10-02 18:35:12 +02:00
|
|
|
array_append SC_CHANGE_LIST "${SC_ROOT}${pkg}"
|
2010-09-20 16:48:39 +02:00
|
|
|
done
|
2010-08-12 22:38:18 +02:00
|
|
|
|
2010-08-12 23:01:43 +02:00
|
|
|
local sdir
|
2010-07-12 13:27:39 +02:00
|
|
|
for sdir in eclass licenses profiles; do
|
2010-08-12 23:01:43 +02:00
|
|
|
check_for_changes ${SC_ROOT}${sdir} >/dev/null && SC_CHANGE_LIST="${SC_CHANGE_LIST} ${SC_ROOT}${sdir}"
|
2010-07-12 13:27:39 +02:00
|
|
|
done
|
|
|
|
SC_SCENARIO=package-removal
|
|
|
|
sayv "We're removing ${SC_CP}."
|
2010-07-12 00:16:24 +02:00
|
|
|
else
|
2010-07-12 13:27:39 +02:00
|
|
|
die 'No familiar scenario found.'
|
2010-07-12 00:16:24 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2010-07-13 17:15:51 +02:00
|
|
|
# -- VCS helpers --
|
|
|
|
|
|
|
|
# Check whether a particular locations have changed, ignoring ChangeLog
|
|
|
|
# changes.
|
2010-07-12 00:16:24 +02:00
|
|
|
check_for_changes() {
|
|
|
|
local output
|
|
|
|
|
|
|
|
if [ ${SC_VCS%-svn} = git ]; then
|
2010-07-13 17:34:42 +02:00
|
|
|
output=$(git diff-index --name-only --relative HEAD -- "${@}")
|
2010-08-24 22:33:16 +02:00
|
|
|
elif [ ${SC_VCS} = hg ]; then
|
|
|
|
output=$(hg status -- ${1-.} "${@}")
|
2010-07-12 14:59:56 +02:00
|
|
|
elif [ ${SC_VCS} = svn ]; then
|
2010-07-13 17:34:42 +02:00
|
|
|
output=$(svn status -- "${@}")
|
2010-10-27 22:22:46 +02:00
|
|
|
elif [ ${SC_VCS} = cvs ]; then
|
|
|
|
# `U' indicates a remote, incomming update.
|
|
|
|
output=$(cvs -n -q update -R -- "${@}" 2>/dev/null | grep -v -e '^U')
|
2010-07-12 00:16:24 +02:00
|
|
|
fi
|
|
|
|
|
2010-07-12 13:27:39 +02:00
|
|
|
[ -z "${output}" ] && return 1
|
2010-07-12 09:39:11 +02:00
|
|
|
# We do not care about user mangling ChangeLog, we will reset it anyway.
|
|
|
|
echo "${output}" | grep -v ChangeLog >/dev/null
|
2010-07-12 00:16:24 +02:00
|
|
|
}
|
|
|
|
|
2010-07-13 17:15:51 +02:00
|
|
|
# Discard any changes to a particular set of files.
|
2010-07-12 00:16:24 +02:00
|
|
|
vcs_reset() {
|
|
|
|
if [ ${SC_VCS%-svn} = git ]; then
|
2010-07-13 18:45:50 +02:00
|
|
|
git checkout HEAD -- "${@}" 2>/dev/null || req rm -f -- "${@}"
|
2010-08-24 22:33:16 +02:00
|
|
|
elif [ ${SC_VCS} = hg ]; then
|
|
|
|
[ -n "$(hg status -au "${@}")" ] && req rm -f -- "${@}"
|
2010-09-15 07:38:17 +02:00
|
|
|
hg revert --no-backup -- "${@}" 2>/dev/null
|
2010-07-12 14:59:56 +02:00
|
|
|
elif [ ${SC_VCS} = svn ]; then
|
2010-07-13 17:34:42 +02:00
|
|
|
req rm -f -- "${@}"
|
2010-07-13 17:39:49 +02:00
|
|
|
svn revert -- "${@}" >/dev/null
|
2010-10-27 22:22:46 +02:00
|
|
|
elif [ ${SC_VCS} = cvs ]; then
|
|
|
|
# cvs update -C does exist, but it sometimes doesn't
|
|
|
|
# work.
|
|
|
|
req rm -f -- "${@}"
|
|
|
|
cvs update -- "${@}" >/dev/null 2>&1
|
2010-07-12 00:16:24 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2010-07-13 17:15:51 +02:00
|
|
|
# Request VCS to provide a verbose status report.
|
2010-07-12 09:39:11 +02:00
|
|
|
vcs_status() {
|
|
|
|
if [ ${SC_VCS%-svn} = git ]; then
|
2010-07-13 17:34:42 +02:00
|
|
|
git status -s -- ${1-.} "${@}"
|
2010-08-24 22:33:16 +02:00
|
|
|
elif [ ${SC_VCS} = hg ]; then
|
|
|
|
hg status -- ${1-.} "${@}"
|
2010-07-12 14:59:56 +02:00
|
|
|
elif [ ${SC_VCS} = svn ]; then
|
2010-07-13 17:34:42 +02:00
|
|
|
svn status -- "${@}"
|
2010-10-27 22:22:46 +02:00
|
|
|
elif [ ${SC_VCS} = cvs ]; then
|
|
|
|
cvs -n -q up -- "${@}" 2>/dev/null | grep -v -e '^U'
|
2010-07-12 13:27:39 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2010-07-13 17:15:51 +02:00
|
|
|
# Add particular files to the repository.
|
2010-07-12 13:43:17 +02:00
|
|
|
vcs_add() {
|
2010-07-13 17:34:42 +02:00
|
|
|
${SC_VCS%-svn} add -- "${@}"
|
2010-07-12 13:43:17 +02:00
|
|
|
}
|
|
|
|
|
2010-07-13 17:15:51 +02:00
|
|
|
# Commit the specified objects using the commit message provided
|
|
|
|
# as the first argument. Does not return.
|
2010-07-12 13:27:39 +02:00
|
|
|
vcs_commit() {
|
|
|
|
local msg
|
|
|
|
msg=${1}
|
|
|
|
shift
|
|
|
|
|
|
|
|
if [ ${SC_VCS%-svn} = git ]; then
|
2010-07-13 17:34:42 +02:00
|
|
|
exec git commit -m "${msg}" ${1+-o} -- "${@}"
|
2010-08-24 22:33:16 +02:00
|
|
|
elif [ ${SC_VCS} = hg ]; then
|
2010-09-20 16:48:39 +02:00
|
|
|
exec hg commit -m "${msg}" -- ${1-.} "${@}"
|
2010-07-12 14:59:56 +02:00
|
|
|
elif [ ${SC_VCS} = svn ]; then
|
2010-07-13 17:34:42 +02:00
|
|
|
exec svn commit -m "${msg}" -- "${@}"
|
2010-10-27 22:22:46 +02:00
|
|
|
elif [ ${SC_VCS} = cvs ]; then
|
|
|
|
exec cvs commit -m "${msg}" -- "${@}"
|
2010-07-12 09:39:11 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2010-07-13 17:15:51 +02:00
|
|
|
# Call VCS to update the working copy to HEAD revision.
|
2010-07-13 12:15:25 +02:00
|
|
|
vcs_update() {
|
2010-08-24 22:33:16 +02:00
|
|
|
# Unlike svn, DVCSes don't push the changes to their origins immediately.
|
|
|
|
# That's why we don't force update to it right here.
|
2010-10-30 11:48:03 +02:00
|
|
|
if [ ${SC_VCS} = svn ]; then
|
2010-10-30 20:17:08 +02:00
|
|
|
sayv "Updating the repository..."
|
2010-10-30 11:48:03 +02:00
|
|
|
svn up -- "${@}" || say "Warning: ${SC_VCS} up failed, trying to proceed anyway."
|
|
|
|
elif [ ${SC_VCS} = cvs ]; then
|
2010-10-30 20:17:08 +02:00
|
|
|
sayv "Updating the repository..."
|
2010-10-30 11:48:03 +02:00
|
|
|
cvs up -d -P -- "${@}" || say "Warning: ${SC_VCS} up failed, trying to proceed anyway."
|
2010-07-13 12:15:25 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2010-07-13 17:15:51 +02:00
|
|
|
# Print the help message.
|
2010-07-12 10:32:18 +02:00
|
|
|
print_help() {
|
|
|
|
cat <<_EOH_
|
|
|
|
Synopsis:
|
|
|
|
sunrise-commit [options] [--] <commit message>
|
|
|
|
|
|
|
|
Options:
|
|
|
|
-?, -h, --help print this message,
|
|
|
|
-V, --version print version string,
|
|
|
|
|
|
|
|
-c, --changelog backwards compat (ignored),
|
2010-07-12 11:27:40 +02:00
|
|
|
-C, --nocolor disable colorful output,
|
2010-07-13 12:15:25 +02:00
|
|
|
-d, --noupdate disable updating the repository,
|
2010-07-12 11:45:15 +02:00
|
|
|
-f, --force force repoman to proceed with the commit,
|
2010-07-13 12:26:14 +02:00
|
|
|
-m, --noformat do not prepend the commit message with package names,
|
|
|
|
-q, --quiet backwards compat (ignored),
|
2010-07-12 11:36:23 +02:00
|
|
|
-t, --trivial trivial changes (do not add a ChangeLog entry),
|
2010-07-12 10:32:18 +02:00
|
|
|
-v, --verbose enable verbose output.
|
|
|
|
_EOH_
|
|
|
|
}
|
|
|
|
|
2010-07-13 17:15:51 +02:00
|
|
|
# Request confirmation before committing. Abort if it is not granted.
|
2010-07-12 13:27:39 +02:00
|
|
|
confirm() {
|
|
|
|
while true; do
|
|
|
|
local answ
|
2010-08-06 08:29:40 +02:00
|
|
|
printf '\n%s' "${WHITE}Commit changes?${RESET} [${BGREEN}Yes${RESET}/${RED}No${RESET}] ${GREEN}" >&2
|
2010-07-12 13:27:39 +02:00
|
|
|
read answ
|
|
|
|
printf '%s' "${RESET}"
|
|
|
|
|
|
|
|
case "${answ}" in
|
|
|
|
[yY]|[yY][eE]|[yY][eE][sS])
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
[nN]|[nN][oO])
|
|
|
|
die 'Aborting.'
|
|
|
|
;;
|
|
|
|
*)
|
2010-07-12 18:18:42 +02:00
|
|
|
say "Your response '${answ}' not understood, try again."
|
2010-07-12 13:27:39 +02:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2010-07-12 00:16:24 +02:00
|
|
|
# Guess what!
|
|
|
|
main() {
|
2010-07-13 12:26:14 +02:00
|
|
|
local commitmsg force monochrome noprepend noupdate trivial
|
2010-07-12 00:16:24 +02:00
|
|
|
unset SC_VERBOSE
|
|
|
|
|
2010-07-13 17:15:51 +02:00
|
|
|
# Command-line parsing.
|
2010-07-12 00:16:24 +02:00
|
|
|
while [ ${#} -gt 0 ]; do
|
|
|
|
case "${1}" in
|
2010-07-12 11:15:51 +02:00
|
|
|
--help|-\?|-h)
|
2010-07-12 10:32:18 +02:00
|
|
|
print_help
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
--version|-V)
|
2010-10-31 16:09:49 +01:00
|
|
|
echo '@PACKAGE_STRING@'
|
2010-07-12 10:32:18 +02:00
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
|
|
|
|
-c|--changelog)
|
|
|
|
# Now changelog entries are implicit -- backwards compat.
|
|
|
|
;;
|
2010-07-12 11:27:40 +02:00
|
|
|
-C|--nocolor)
|
|
|
|
monochrome=1
|
|
|
|
;;
|
2010-07-13 12:15:25 +02:00
|
|
|
-d|--noupdate)
|
|
|
|
noupdate=1
|
|
|
|
;;
|
2010-07-12 11:45:15 +02:00
|
|
|
-f|--force)
|
|
|
|
force=1
|
|
|
|
;;
|
2010-07-13 12:26:14 +02:00
|
|
|
-m|--noformat)
|
|
|
|
noprepend=
|
|
|
|
;;
|
|
|
|
-q|--quiet)
|
|
|
|
;;
|
2010-07-12 11:36:23 +02:00
|
|
|
-t|--trivial)
|
|
|
|
trivial=1
|
|
|
|
;;
|
2010-07-12 00:16:24 +02:00
|
|
|
-v|--verbose)
|
|
|
|
SC_VERBOSE=1
|
|
|
|
;;
|
2010-07-12 10:32:18 +02:00
|
|
|
|
2010-07-12 00:16:24 +02:00
|
|
|
--)
|
|
|
|
shift
|
2010-10-02 18:35:12 +02:00
|
|
|
array_append commitmsg "${@}"
|
2010-07-12 00:16:24 +02:00
|
|
|
break
|
|
|
|
;;
|
2010-07-12 13:47:50 +02:00
|
|
|
-*)
|
|
|
|
die "Unknown option: ${1}; see --help." >&2
|
|
|
|
;;
|
2010-07-12 00:16:24 +02:00
|
|
|
*)
|
2010-10-02 18:35:12 +02:00
|
|
|
array_append commitmsg "${1}"
|
2010-07-12 00:16:24 +02:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2010-07-13 17:15:51 +02:00
|
|
|
# Initialize colors.
|
2010-07-12 11:27:40 +02:00
|
|
|
if [ -n "${monochrome}" ]; then
|
|
|
|
RESET=
|
|
|
|
RED=
|
|
|
|
GREEN=
|
|
|
|
BGREEN=
|
|
|
|
YELLOW=
|
|
|
|
WHITE=
|
|
|
|
else
|
|
|
|
local esc
|
|
|
|
esc=$(printf '\033[')
|
|
|
|
|
|
|
|
RESET=${esc}0m
|
|
|
|
RED="${esc}1;31m"
|
|
|
|
GREEN=${esc}32m
|
|
|
|
BGREEN="${esc}1;32m"
|
|
|
|
YELLOW="${esc}1;33m"
|
|
|
|
WHITE="${esc}1;37m"
|
|
|
|
fi
|
|
|
|
|
2010-07-12 00:16:24 +02:00
|
|
|
[ -n "${commitmsg}" ] || die 'No commit message provided.'
|
|
|
|
|
2010-07-13 17:15:51 +02:00
|
|
|
# Look around.
|
2010-07-12 00:16:24 +02:00
|
|
|
find_repo
|
|
|
|
find_ebuilds
|
|
|
|
|
|
|
|
case ${SC_SCENARIO} in
|
2010-07-13 17:15:51 +02:00
|
|
|
# Committing changes within the ebuild directory.
|
|
|
|
# This includes committing new ebuilds.
|
2010-07-12 00:16:24 +02:00
|
|
|
ebuild-commit)
|
|
|
|
check_for_changes || die 'No changes found to commit.'
|
|
|
|
|
2010-10-30 11:48:59 +02:00
|
|
|
if [ -z "${noupdate}" ]; then
|
|
|
|
vcs_update
|
|
|
|
fi
|
|
|
|
|
2010-08-24 22:33:16 +02:00
|
|
|
# With DVCS repos, we do not do ChangeLogs by default...
|
2010-07-12 00:16:24 +02:00
|
|
|
# ...at least unless they're already there.
|
2010-10-28 18:38:49 +02:00
|
|
|
if [ ${SC_VCS#git-} = svn -o ${SC_VCS} = cvs -o -f ChangeLog ]; then
|
2010-07-12 00:16:24 +02:00
|
|
|
sayv 'Cleaning up the ChangeLog...'
|
|
|
|
vcs_reset ChangeLog
|
2010-07-12 09:39:11 +02:00
|
|
|
|
|
|
|
local bns
|
|
|
|
# Let's take a lucky guess bugnumbers consist of 4+ digits.
|
2010-07-12 11:30:54 +02:00
|
|
|
bns=$(echo "${commitmsg}" | grep -o -E '[0-9]{4,}')
|
2010-07-12 09:39:11 +02:00
|
|
|
|
|
|
|
# Creating a new ChangeLog? Let's take a look at the commit message.
|
2010-07-12 11:36:23 +02:00
|
|
|
if [ ! -f ChangeLog ]; then
|
|
|
|
[ -n "${trivial}" ] && die "Trivial change for an initial commit? You're joking, right?"
|
2010-07-13 18:41:13 +02:00
|
|
|
|
|
|
|
# Sunrise-specific checks.
|
|
|
|
if [ "$(cat ../../profiles/repo_name 2>/dev/null)" = "sunrise" ]; then
|
|
|
|
[ -z "${bns}" ] && die 'Please supply the bug number in the initial commit message!'
|
|
|
|
if [ ! -f metadata.xml ]; then
|
|
|
|
req cp ../../skel.metadata.xml metadata.xml
|
|
|
|
# Output similar to echangelog.
|
|
|
|
diff -dup /dev/null metadata.xml
|
|
|
|
req vcs_add metadata.xml
|
|
|
|
fi
|
2010-07-12 13:43:17 +02:00
|
|
|
fi
|
2010-07-12 11:36:23 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "${trivial}" ]; then
|
|
|
|
sayv '...and appending to it.'
|
2010-07-12 18:18:42 +02:00
|
|
|
echangelog "${commitmsg}" || die 'Please correct the problems shown by echangelog.'
|
2010-07-12 11:36:23 +02:00
|
|
|
echo
|
|
|
|
fi
|
2010-07-12 09:39:11 +02:00
|
|
|
|
|
|
|
if [ -n "${bns}" ]; then
|
2010-07-12 11:27:40 +02:00
|
|
|
local bn cbn
|
2010-07-12 09:39:11 +02:00
|
|
|
for bn in ${bns}; do
|
2010-07-12 11:27:40 +02:00
|
|
|
cbn=#${WHITE}${bn}${NORMAL}
|
2010-07-12 15:03:31 +02:00
|
|
|
wget -q http://bugs.gentoo.org/show_bug.cgi?id=${bn} -O - | sed -n \
|
|
|
|
-e "s, *<title>Gentoo Bug \([0-9]*\) - \(.*\)</title>,Bug ${cbn}: ${BGREEN}\2${RESET},p" \
|
|
|
|
-e "s, *<title>Gentoo \(Invalid Bug ID\)</title>,Bug ${cbn}: ${YELLOW}!! \1${RESET},p"
|
2010-07-12 09:39:11 +02:00
|
|
|
done
|
|
|
|
echo
|
|
|
|
fi
|
2010-07-12 00:16:24 +02:00
|
|
|
fi
|
|
|
|
|
2010-10-30 11:44:54 +02:00
|
|
|
if [ ${SC_VCS} != cvs -o -n "${noupdate}" ]; then
|
|
|
|
vcs_status
|
|
|
|
fi
|
2010-07-12 09:39:11 +02:00
|
|
|
echo
|
|
|
|
|
2010-07-13 17:15:51 +02:00
|
|
|
# Since commit 32264c3, repoman supports '--ask' option,
|
|
|
|
# which requests user confirmation before the commit.
|
|
|
|
# We like that, because it does it in the right place.
|
|
|
|
#
|
|
|
|
# If user is using earlier repoman version, we need to
|
|
|
|
# request that confirmation ourselves. As we would like
|
|
|
|
# the user to see 'repoman full' results first, we need
|
|
|
|
# to call it ourselves. Moreover, it requires Manifest to be
|
|
|
|
# up-to-date, so we need to call 'repoman manifest' too.
|
|
|
|
#
|
|
|
|
# That's pretty sad, because it means we're wasting time
|
|
|
|
# calling the same repoman functions twice (once manually,
|
|
|
|
# then within 'repoman commit'). That's why we would be
|
|
|
|
# happy if user updated his/her Portage, and we'd like to
|
|
|
|
# encourage him/her to do so -- but we'll have to delay that
|
|
|
|
# until a new Portage version is released.
|
|
|
|
|
2010-07-12 10:20:31 +02:00
|
|
|
local old_repoman
|
|
|
|
repoman --version -a >/dev/null 2>&1
|
2010-07-13 17:34:42 +02:00
|
|
|
if [ ${?} -eq 2 ]; then
|
2010-07-12 10:20:31 +02:00
|
|
|
old_repoman=
|
|
|
|
|
2010-07-12 15:31:47 +02:00
|
|
|
#say "${GREEN}Please consider updating portage to newer version.${RESET}"
|
|
|
|
#say
|
|
|
|
req repoman manifest
|
|
|
|
if ! repoman full; then
|
2010-07-12 18:18:42 +02:00
|
|
|
[ -n "${force}" ] || die 'Please correct the problems shown by repoman.'
|
2010-07-12 15:31:47 +02:00
|
|
|
fi
|
2010-07-12 13:27:39 +02:00
|
|
|
confirm
|
2010-07-12 10:20:31 +02:00
|
|
|
fi
|
|
|
|
|
2010-10-28 18:38:10 +02:00
|
|
|
# In CVS, we don't prepend the package name to the commit message.
|
|
|
|
[ ${SC_VCS} = cvs ] && noprepend=
|
|
|
|
|
2010-07-12 00:16:24 +02:00
|
|
|
sayv "Now, let's let repoman do its job..."
|
2010-07-13 12:26:14 +02:00
|
|
|
exec repoman commit ${old_repoman--a} ${force+-f} -m "${noprepend-${SC_CP}: }${commitmsg}"
|
2010-07-12 00:16:24 +02:00
|
|
|
;;
|
2010-07-13 17:15:51 +02:00
|
|
|
|
|
|
|
# Clean removal of a package set.
|
2010-07-12 13:27:39 +02:00
|
|
|
package-removal)
|
|
|
|
vcs_status ${SC_CHANGE_LIST}
|
|
|
|
echo
|
2010-08-12 23:01:43 +02:00
|
|
|
|
|
|
|
local pkg regex
|
|
|
|
regex=
|
|
|
|
for pkg in ${SC_REMOVED_PACKAGE_LIST}; do
|
2010-10-02 18:35:12 +02:00
|
|
|
regex=${regex:+${regex}\|}${pkg}
|
2010-08-12 23:01:43 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
say "${GREEN}Grepping for package references...${RESET}"
|
|
|
|
# -n is for line numbers, -C would be non-POSIX
|
2010-09-20 16:20:52 +02:00
|
|
|
if grep -n "${regex}" ${SC_ROOT}*/*/*.ebuild ${SC_ROOT}*/*/metadata.xml ${SC_ROOT}profiles/package.mask 2>/dev/null; then
|
2010-08-12 23:01:43 +02:00
|
|
|
echo
|
|
|
|
[ -n "${force}" ] || die 'Please remove the removed package references or use --force.'
|
|
|
|
else
|
|
|
|
echo
|
|
|
|
fi
|
|
|
|
|
2010-08-12 22:38:18 +02:00
|
|
|
say "Ready to commit ${WHITE}$(echo ${SC_REMOVED_PACKAGE_LIST} | wc -w)${RESET} package removal(s), with commit message:"
|
2010-07-12 13:27:39 +02:00
|
|
|
say "${BGREEN}${SC_CP}: ${commitmsg}${RESET}"
|
|
|
|
confirm
|
2010-07-13 12:15:25 +02:00
|
|
|
|
2010-10-27 22:27:20 +02:00
|
|
|
if [ -z "${noupdate}" ]; then
|
2010-07-13 12:15:25 +02:00
|
|
|
vcs_update ${SC_CHANGE_LIST}
|
|
|
|
fi
|
|
|
|
|
2010-07-13 12:26:14 +02:00
|
|
|
vcs_commit "${noprepend-${SC_CP}: }${commitmsg}" ${SC_CHANGE_LIST}
|
2010-07-12 13:27:39 +02:00
|
|
|
;;
|
2010-07-12 00:16:24 +02:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
main "${@}"
|