mirror of
https://src.fedoraproject.org/rpms/grub2.git
synced 2024-11-24 06:22:43 +00:00
do-rebase: refactor command line parameters
Removes the logic to search for a distro release version based on the --dist argument and instead makes this as required parameter provided by the user, reducing code size considerably as the expense of letting the user responsibility to define it. The --dist argument was also used as branch name in some cases (where --dist was not defined) so this change splits the original parameter semantic in two: one for defining the distro release version (--dist) and another to define the branch name (--branch). Finally, a short README with single scenario as example. Signed-off-by: Leo Sandoval <lsandova@redhat.com>
This commit is contained in:
parent
0a3394ca4b
commit
9eb852fbc5
3 changed files with 61 additions and 69 deletions
21
README.do-rebase
Normal file
21
README.do-rebase
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
do-rebase script
|
||||||
|
================
|
||||||
|
|
||||||
|
The `do-rebase` is a useful script that helps the developers to take patches from
|
||||||
|
a remote repository & branch, apply those and create a commit. Although this sounds like
|
||||||
|
easy steps, each may take time and it is prone to errors (as any manual work).
|
||||||
|
|
||||||
|
To see in action, supposed you have a one or more patches for `f42` release that fixes (or
|
||||||
|
enhances) a bug at the repository `git@github.com:someuser/grub2.git` with branch
|
||||||
|
name `hotfix`; the way to call the script is by
|
||||||
|
|
||||||
|
$ ./do-rebase --dist=f42 --repo=git@github.com:someuser/grub2.git --branch=hotfix
|
||||||
|
|
||||||
|
the script will then fetch the repository in a separate directory (`.rhboot.git`), compare
|
||||||
|
those `hotfix` commits that has not been merged in `master` (`git format-patch master..hotfix`
|
||||||
|
on the `.rhboot.git` repo), replace these with the ones in current working dir, finally create
|
||||||
|
a commit that you can of course amend.
|
||||||
|
|
||||||
|
The script supports other useful options: `--amend --commit --nocommit --bumpspec --nobumpspec --pkgtool=<PACKAGE_TOOL>`.
|
||||||
|
Worth mentioning that you do not have to specify a --pkgtool option: it is infered from the --dist parameter but in
|
||||||
|
case you want to override it, the options is there.
|
104
do-rebase
104
do-rebase
|
@ -1,6 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
set -u
|
set -u
|
||||||
|
|
||||||
shopt -qu globstar
|
shopt -qu globstar
|
||||||
shopt -qs expand_aliases
|
shopt -qs expand_aliases
|
||||||
export LC_COLLATE=C
|
export LC_COLLATE=C
|
||||||
|
@ -18,24 +19,33 @@ usage()
|
||||||
exec 1>&2
|
exec 1>&2
|
||||||
retcode=$1
|
retcode=$1
|
||||||
fi
|
fi
|
||||||
echo usage: "do-rebase [OPTIONS] [--dist RELEASEVER | RELEASEVER ] [GITREPO]"
|
echo usage: "do-rebase [OPTIONS] --dist=<RELEASE_VER> --repo=<REPOSITORY> --branch=<BRANCH>"
|
||||||
echo OPTIONS: --dist=RELEASEVER --repo=REPO --amend --nocommit --nobumpspec
|
echo OPTIONS: "--amend --commit --nocommit --bumpspec --nobumpspec"
|
||||||
exit $retcode
|
exit "$retcode"
|
||||||
}
|
}
|
||||||
|
|
||||||
if ! git status | grep -q 'nothing to commit, working .* clean' ; then
|
on_error() {
|
||||||
|
exec 1>&2
|
||||||
|
echo "An error occurred. Exiting..."
|
||||||
|
git reset --hard
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
trap 'on_error' ERR
|
||||||
|
|
||||||
|
# Check if the working directory is clean (no changes)
|
||||||
|
if ! git diff-index --quiet HEAD --; then
|
||||||
echo "Working directory is not clean, cannot rebase." 1>&2
|
echo "Working directory is not clean, cannot rebase." 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
gitrepo="git@github.com:rhboot/grub2.git"
|
gitrepo=""
|
||||||
|
branch=""
|
||||||
releasever=""
|
releasever=""
|
||||||
amend=""
|
amend=""
|
||||||
commit=1
|
commit=1
|
||||||
bumpspec=1
|
bumpspec=1
|
||||||
|
|
||||||
declare -a savedargs
|
|
||||||
savedargs=()
|
|
||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
--help|-h|--usage|-?|-u)
|
--help|-h|--usage|-?|-u)
|
||||||
|
@ -55,6 +65,13 @@ while [ $# -gt 0 ]; do
|
||||||
shift
|
shift
|
||||||
gitrepo=$1
|
gitrepo=$1
|
||||||
;;
|
;;
|
||||||
|
--branch=*)
|
||||||
|
branch=${1##--branch=}
|
||||||
|
;;
|
||||||
|
--branch)
|
||||||
|
shift
|
||||||
|
branch=$1
|
||||||
|
;;
|
||||||
--amend)
|
--amend)
|
||||||
amend="--amend"
|
amend="--amend"
|
||||||
;;
|
;;
|
||||||
|
@ -74,93 +91,44 @@ while [ $# -gt 0 ]; do
|
||||||
bumpspec=0
|
bumpspec=0
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
savedargs[${#savedargs[@]}]="$1"
|
echo "Unknown parameter $1"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
set -- "${savedargs[@]}"
|
|
||||||
|
|
||||||
if [ -z "${releasever}" -a $# -gt 0 ]; then
|
# check must params
|
||||||
releasever=$1
|
if [ -z "$releasever" ] || [ -z "$gitrepo" ] || [ -z "$branch" ]; then
|
||||||
shift
|
usage
|
||||||
else
|
|
||||||
dist=$(git status | grep "On branch" | cut -d\ -f3-)
|
|
||||||
if [ -z "$dist" ]; then
|
|
||||||
echo "Could not figure out distro release version" 1>&2
|
|
||||||
usage 1
|
|
||||||
fi
|
|
||||||
case "$(eval echo \${dist})" in
|
|
||||||
.fc*)
|
|
||||||
releasever=$(echo ${dist} | \
|
|
||||||
sed 's/^\.fc\([[:digit:]]\+\)$/fedora-\1/')
|
|
||||||
;;
|
|
||||||
.*)
|
|
||||||
releasever=$(echo $dist | \
|
|
||||||
sed 's/^\.\([[:alpha:]]\+\)\([[:digit:]]\+\)$/\1-\2/')
|
|
||||||
;;
|
|
||||||
rhel*)
|
|
||||||
releasever=${dist}
|
|
||||||
dist=.el${releasever##rhel-}
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
if [ -z "${releasever}" -o "${releasever}" = "${dist}" ]; then
|
|
||||||
echo "Could not figure out distro release version" 1>&2
|
|
||||||
usage 1
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$releasever" ]; then
|
if [ ! -d "$PWD/.rhboot.git" ]; then
|
||||||
echo "Could not figure out distro release version" 1>&2
|
|
||||||
usage 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "${1:-}" ]; then
|
|
||||||
gitrepo=$1
|
|
||||||
shift
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $# -ge 1 ]; then
|
|
||||||
echo "Unknown argument \"$1\"" 1>&2
|
|
||||||
usage 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -d $PWD/.rhboot.git ]; then
|
|
||||||
othergit init
|
othergit init
|
||||||
othergit config core.abbrev 11
|
othergit config core.abbrev 11
|
||||||
if ! othergit remote add \
|
if ! othergit remote add rhboot "$gitrepo" >/dev/null 2>&1 ; then
|
||||||
rhboot $gitrepo \
|
|
||||||
>/dev/null 2>&1 ; then
|
|
||||||
echo "Could not add remote: rhboot" 1>&2
|
echo "Could not add remote: rhboot" 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
elif othergit remote show -n rhboot | grep -q "URL: github$" ; then
|
elif othergit remote show -n rhboot | grep -q "URL: github$" ; then
|
||||||
if ! othergit remote add \
|
if ! othergit remote add rhboot "$gitrepo" >/dev/null 2>&1 ; then
|
||||||
rhboot $gitrepo \
|
|
||||||
>/dev/null 2>&1 ; then
|
|
||||||
echo "Could not add remote: rhboot" 1>&2
|
echo "Could not add remote: rhboot" 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
othergit remote set-url rhboot ${gitrepo}
|
othergit remote set-url rhboot "${gitrepo}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
othergit fetch rhboot
|
othergit fetch rhboot
|
||||||
remote=$(othergit branch --list -r "rhboot/${releasever}" 2>/dev/null)
|
|
||||||
if [ "${remote}" != " rhboot/${releasever}" ]; then
|
|
||||||
echo branch \"${releasever}\" does not appear to exist 1>&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
unset LC_ALL
|
unset LC_ALL
|
||||||
git rm -q 0*.patch
|
git rm -q 0*.patch
|
||||||
|
|
||||||
fedpkg sources
|
fedpkg --release "$releasever" sources
|
||||||
|
|
||||||
> grub.patches
|
> grub.patches
|
||||||
patches=$(formatpatch refs/remotes/rhboot/master..refs/remotes/rhboot/${releasever})
|
patches=$(formatpatch refs/remotes/rhboot/master..refs/remotes/rhboot/"${branch}")
|
||||||
for x in $patches ; do
|
for x in $patches ; do
|
||||||
echo Patch$(echo ${x} | cut -d- -f1): ${x} >> grub.patches
|
echo "Patch$(echo "${x}" | cut -d- -f1): ${x}" >> grub.patches
|
||||||
done
|
done
|
||||||
if [[ -z "$amend" && ${bumpspec} -gt 0 ]] || [[ ${bumpspec} -ge 2 ]] ; then
|
if [[ -z "$amend" && ${bumpspec} -gt 0 ]] || [[ ${bumpspec} -ge 2 ]] ; then
|
||||||
rpmdev-bumpspec -c "- Rebased to newer upstream for ${releasever}" grub2.spec
|
rpmdev-bumpspec -c "- Rebased to newer upstream for ${releasever}" grub2.spec
|
||||||
|
@ -168,7 +136,7 @@ fi
|
||||||
git add 0*.patch grub2.spec grub.patches
|
git add 0*.patch grub2.spec grub.patches
|
||||||
if [[ ${commit} -eq 1 ]] ; then
|
if [[ ${commit} -eq 1 ]] ; then
|
||||||
if [ -z "$amend" ]; then
|
if [ -z "$amend" ]; then
|
||||||
fedpkg commit -s -c
|
fedpkg --release "$releasever" commit -s -c
|
||||||
else
|
else
|
||||||
git commit --amend
|
git commit --amend
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
Name: grub2
|
Name: grub2
|
||||||
Epoch: 1
|
Epoch: 1
|
||||||
Version: 2.12
|
Version: 2.12
|
||||||
Release: 11%{?dist}
|
Release: 12%{?dist}
|
||||||
Summary: Bootloader with support for Linux, Multiboot and more
|
Summary: Bootloader with support for Linux, Multiboot and more
|
||||||
License: GPL-3.0-or-later
|
License: GPL-3.0-or-later
|
||||||
URL: http://www.gnu.org/software/grub/
|
URL: http://www.gnu.org/software/grub/
|
||||||
|
@ -560,6 +560,9 @@ mv ${EFI_HOME}/grub.cfg.stb ${EFI_HOME}/grub.cfg
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Wed Oct 23 2024 Leo Sandoval <lsandova@redhat.com> 2.12-12
|
||||||
|
- do-rebase: refactor command line parameters
|
||||||
|
|
||||||
* Wed Oct 23 2024 Nicolas Frayer <nfrayer@redhat.com> 2.12-11
|
* Wed Oct 23 2024 Nicolas Frayer <nfrayer@redhat.com> 2.12-11
|
||||||
- cmd/search: Fix a possible NULL ptr dereference
|
- cmd/search: Fix a possible NULL ptr dereference
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue