2016-02-17 00:06:49 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
2017-06-16 19:21:18 +00:00
|
|
|
set -u
|
2024-10-21 18:08:48 +00:00
|
|
|
|
2016-02-17 00:06:49 +00:00
|
|
|
shopt -qu globstar
|
2017-06-16 19:21:18 +00:00
|
|
|
shopt -qs expand_aliases
|
2016-02-17 00:06:49 +00:00
|
|
|
export LC_COLLATE=C
|
|
|
|
export LC_ALL=C
|
|
|
|
|
2018-10-23 10:03:52 +00:00
|
|
|
diff_ops="-O.git.diff.order --patience -l0"
|
|
|
|
format_patch_ops="--zero-commit --no-signature --no-numbered --stat=80 --summary $diff_ops"
|
2017-06-16 19:21:18 +00:00
|
|
|
alias othergit="GIT_DIR=$PWD/.rhboot.git GIT_WORK_TREE=$PWD git"
|
2018-05-11 14:33:02 +00:00
|
|
|
alias formatpatch="othergit format-patch $format_patch_ops"
|
2017-06-16 19:21:18 +00:00
|
|
|
|
2016-02-17 00:06:49 +00:00
|
|
|
usage()
|
|
|
|
{
|
|
|
|
retcode=0
|
2018-05-14 15:43:51 +00:00
|
|
|
if [ -n "${1:-}" ]; then
|
2016-02-17 00:06:49 +00:00
|
|
|
exec 1>&2
|
|
|
|
retcode=$1
|
|
|
|
fi
|
2024-10-21 18:08:48 +00:00
|
|
|
echo usage: "do-rebase [OPTIONS] --dist=<RELEASE_VER> --repo=<REPOSITORY> --branch=<BRANCH>"
|
|
|
|
echo OPTIONS: "--amend --commit --nocommit --bumpspec --nobumpspec"
|
|
|
|
exit "$retcode"
|
|
|
|
}
|
|
|
|
|
|
|
|
on_error() {
|
|
|
|
exec 1>&2
|
|
|
|
echo "An error occurred. Exiting..."
|
|
|
|
git reset --hard
|
|
|
|
exit 1
|
2016-02-17 00:06:49 +00:00
|
|
|
}
|
|
|
|
|
2024-10-21 18:08:48 +00:00
|
|
|
trap 'on_error' ERR
|
|
|
|
|
|
|
|
# Check if the working directory is clean (no changes)
|
|
|
|
if ! git diff-index --quiet HEAD --; then
|
2016-02-17 00:06:49 +00:00
|
|
|
echo "Working directory is not clean, cannot rebase." 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-10-21 18:08:48 +00:00
|
|
|
gitrepo=""
|
|
|
|
branch=""
|
2016-02-17 00:06:49 +00:00
|
|
|
releasever=""
|
2016-04-07 14:44:51 +00:00
|
|
|
amend=""
|
2018-07-10 18:39:10 +00:00
|
|
|
commit=1
|
|
|
|
bumpspec=1
|
2016-02-17 00:06:49 +00:00
|
|
|
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
case $1 in
|
|
|
|
--help|-h|--usage|-?|-u)
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
--dist=*)
|
|
|
|
releasever=${1##--dist=}
|
|
|
|
;;
|
|
|
|
--dist)
|
|
|
|
shift
|
|
|
|
releasever=$1
|
|
|
|
;;
|
2018-05-14 15:43:52 +00:00
|
|
|
--repo=*)
|
|
|
|
gitrepo=${1##--repo=}
|
|
|
|
;;
|
|
|
|
--repo)
|
|
|
|
shift
|
|
|
|
gitrepo=$1
|
|
|
|
;;
|
2024-10-21 18:08:48 +00:00
|
|
|
--branch=*)
|
|
|
|
branch=${1##--branch=}
|
|
|
|
;;
|
|
|
|
--branch)
|
|
|
|
shift
|
|
|
|
branch=$1
|
|
|
|
;;
|
2016-04-07 14:44:51 +00:00
|
|
|
--amend)
|
|
|
|
amend="--amend"
|
|
|
|
;;
|
2018-07-10 18:39:10 +00:00
|
|
|
--commit)
|
|
|
|
commit=1
|
|
|
|
;;
|
2018-07-11 19:52:37 +00:00
|
|
|
--nocommit|--no-commit|--nc)
|
2018-07-10 18:39:10 +00:00
|
|
|
# --nocommit implies nobumpspec, but --bumpspec after it will
|
|
|
|
# force bumpspec to get run.
|
|
|
|
commit=0
|
|
|
|
bumpspec=0
|
|
|
|
;;
|
|
|
|
--bumpspec)
|
|
|
|
bumpspec=2
|
|
|
|
;;
|
2018-07-11 19:52:37 +00:00
|
|
|
--nobumpspec|--no-bumpspec|--nb)
|
2018-07-10 18:39:10 +00:00
|
|
|
bumpspec=0
|
|
|
|
;;
|
2016-02-17 00:06:49 +00:00
|
|
|
*)
|
2024-10-21 18:08:48 +00:00
|
|
|
echo "Unknown parameter $1"
|
2016-02-17 00:06:49 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2024-10-21 18:08:48 +00:00
|
|
|
# check must params
|
|
|
|
if [ -z "$releasever" ] || [ -z "$gitrepo" ] || [ -z "$branch" ]; then
|
|
|
|
usage
|
2016-02-17 00:06:49 +00:00
|
|
|
fi
|
|
|
|
|
2024-10-21 18:08:48 +00:00
|
|
|
if [ ! -d "$PWD/.rhboot.git" ]; then
|
2017-06-16 19:21:18 +00:00
|
|
|
othergit init
|
2018-10-23 10:03:52 +00:00
|
|
|
othergit config core.abbrev 11
|
2024-10-21 18:08:48 +00:00
|
|
|
if ! othergit remote add rhboot "$gitrepo" >/dev/null 2>&1 ; then
|
2017-06-16 19:21:18 +00:00
|
|
|
echo "Could not add remote: rhboot" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
elif othergit remote show -n rhboot | grep -q "URL: github$" ; then
|
2024-10-21 18:08:48 +00:00
|
|
|
if ! othergit remote add rhboot "$gitrepo" >/dev/null 2>&1 ; then
|
2017-06-16 19:21:18 +00:00
|
|
|
echo "Could not add remote: rhboot" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2018-07-17 20:30:53 +00:00
|
|
|
else
|
2024-10-21 18:08:48 +00:00
|
|
|
othergit remote set-url rhboot "${gitrepo}"
|
2016-02-17 00:06:49 +00:00
|
|
|
fi
|
|
|
|
|
2017-06-16 19:21:18 +00:00
|
|
|
othergit fetch rhboot
|
2016-02-17 00:06:49 +00:00
|
|
|
|
|
|
|
unset LC_ALL
|
|
|
|
git rm -q 0*.patch
|
|
|
|
|
2024-10-21 18:08:48 +00:00
|
|
|
fedpkg --release "$releasever" sources
|
2018-07-27 16:57:04 +00:00
|
|
|
|
2017-06-16 19:21:18 +00:00
|
|
|
> grub.patches
|
2024-10-21 18:08:48 +00:00
|
|
|
patches=$(formatpatch refs/remotes/rhboot/master..refs/remotes/rhboot/"${branch}")
|
2016-02-17 00:06:49 +00:00
|
|
|
for x in $patches ; do
|
2024-10-21 18:08:48 +00:00
|
|
|
echo "Patch$(echo "${x}" | cut -d- -f1): ${x}" >> grub.patches
|
2016-02-17 00:06:49 +00:00
|
|
|
done
|
2018-07-10 18:39:10 +00:00
|
|
|
if [[ -z "$amend" && ${bumpspec} -gt 0 ]] || [[ ${bumpspec} -ge 2 ]] ; then
|
2016-04-07 14:44:51 +00:00
|
|
|
rpmdev-bumpspec -c "- Rebased to newer upstream for ${releasever}" grub2.spec
|
|
|
|
fi
|
2017-06-16 19:21:18 +00:00
|
|
|
git add 0*.patch grub2.spec grub.patches
|
2018-07-10 18:39:10 +00:00
|
|
|
if [[ ${commit} -eq 1 ]] ; then
|
|
|
|
if [ -z "$amend" ]; then
|
2024-10-21 18:08:48 +00:00
|
|
|
fedpkg --release "$releasever" commit -s -c
|
2018-07-10 18:39:10 +00:00
|
|
|
else
|
|
|
|
git commit --amend
|
|
|
|
fi
|
2016-04-07 14:44:51 +00:00
|
|
|
fi
|