Commit ce0688f8 authored by Vitaly Lipatov's avatar Vitaly Lipatov

rpmbph: move branch selection code to a separate functions

parent 0b708ca1
#!/bin/bash
# 2003-2010, 2012, 2015 (c) Etersoft www.etersoft.ru
# 2003-2010, 2012, 2015, 2017 (c) Etersoft www.etersoft.ru
# Author: Vitaly Lipatov <lav@etersoft.ru>
# Public domain
#
......@@ -9,7 +9,7 @@
# load common functions, compatible with local and installed script
. `dirname $0`/../share/eterbuild/functions/common
load_mod repl rpm git buildsrpm spec
load_mod repl rpm git buildsrpm spec branch
#############################
......@@ -107,53 +107,23 @@ if [ "$PKGVENDOR" = "alt" ] && is_gear $SPECDIR ; then
set_specdir $SPEC
docmd cd $SPECDIR || fatal
# TODO: move branch detection to a separate function
#[ -f "$LISTNAMES" ] || fatal "Run with one spec inside gear repo"
USEBRANCH=$BINARYREPO
# support for obsoleted M?? names
OLDBRANCH=$MDISTR
if [ "$OLDBRANCH" != "$USEBRANCH" ] ; then
if is_exist_branch $OLDBRANCH ; then
echo "Exists $OLDBRANCH branch, will use it instead $USEBRANCH"
USEBRANCH=$OLDBRANCH
fi
fi
# set branch name
# spec name for branch
BPSPEC=$SPEC.$USEBRANCH
#[ -f "$BPSPEC" ] && fatal "File $BPSPEC is already exists, check it and remove"
cp -f $SPEC $BPSPEC || fatal "Can't copy to $BPSPEC"
CURBRANCH=$(cat $(get_root_git_dir)/.git/.rpmbph.current 2>/dev/null)
if [ -n "$CURBRANCH" ] ; then
echog "Autorestore from broken build..."
docmd git checkout $CURBRANCH
rm -fv $(get_root_git_dir)/.git/.rpmbph.current
rm -fv $BPSPEC $BPSPEC.*
fi
[ -f "$BPSPEC" ] && fatal "File $BPSPEC is already exists, check it and remove"
cp -f $SPEC $BPSPEC || fatal
CURBRANCH=$(get_current_branch)
# TODO: move to a separate function
if [ "$CURBRANCH" = "$USEBRANCH" ] || [ "$CURBRANCH" = "$OLDBRANCH" ] ; then
fatal "You are already in backported branch $CURBRANCH. Run rpmbph in sisyphus or master branch only."
fi
echo "$CURBRANCH" > $(get_root_git_dir)/.git/.rpmbph.current
# Create branch if not exist yet
if ! is_exist_branch $USEBRANCH ; then
docmd git branch $USEBRANCH
fi
# set USEBRANCH CURBRANCH
# checkout to $USERBRANCH
checkout_bpbranch
# backport spec
docmd $ETERBUILDBIN/rpmbps -b $BINARYREPO $BPSPEC || fatal
docmd git checkout $USEBRANCH || fatal "Can't checkout branch $USEBRANCH. Use $BPSPEC manually or remove it."
# TODO: check result message for merge?
# Use heads/ against warning: refname 'branch-name' is ambiguous
docmd git merge --no-ff heads/$CURBRANCH
# override spec conflicts
mv -f $BPSPEC $SPEC || fatal
# FIXME: Ctrl-\ and q will cancelled less with return error code
if [ -z "$QUIET" ] && tty -s && ! ( echo "etersoft-build-utils INFO: Please check diff for backported spec:" ; echo "# etersoft-build-utils NOTE: You can press Ctrl-\ before quit for cancel process."; echo ; git diff $USEBRANCH ) | less; then
......@@ -176,9 +146,8 @@ if [ "$PKGVENDOR" = "alt" ] && is_gear $SPECDIR ; then
set_specdir $SPEC
docmd cd $SPECDIR || fatal
CURBRANCH=$(cat $(get_root_git_dir)/.git/.rpmbph.current)
rm -f $(get_root_git_dir)/.git/.rpmbph.current
docmd git checkout $CURBRANCH || RET=$?
# return to CURBRANCH
checkout_original_branch || RET=$?
cd - >/dev/null
done
......
#!/bin/bash
# 2003-2010, 2012, 2015, 2017 (c) Etersoft www.etersoft.ru
# Author: Vitaly Lipatov <lav@etersoft.ru>
# Public domain
# used: BINARYREPO MDISTR BPSPEC
# set: USEBRANCH CURBRANCH
checkout_bpbranch()
{
#[ -f "$LISTNAMES" ] || fatal "Run with one spec inside gear repo"
USEBRANCH=$BINARYREPO
# TODO: drop support of it
# support for obsoleted M?? names
OLDBRANCH=$MDISTR
if [ "$OLDBRANCH" != "$USEBRANCH" ] ; then
if is_exist_branch $OLDBRANCH ; then
echo "Exists $OLDBRANCH branch, will use it instead $USEBRANCH"
USEBRANCH=$OLDBRANCH
fi
fi
CURBRANCH=$(cat $(get_root_git_dir)/.git/.rpmbph.current 2>/dev/null)
if [ -n "$CURBRANCH" ] ; then
echog "Autorestore from broken build..."
docmd git checkout $CURBRANCH
rm -fv $(get_root_git_dir)/.git/.rpmbph.current
#rm -fv $BPSPEC $BPSPEC.*
rm -fv $BPSPEC.*
fi
CURBRANCH=$(get_current_branch)
# TODO: move to a separate function
if [ "$CURBRANCH" = "$USEBRANCH" ] || [ "$CURBRANCH" = "$OLDBRANCH" ] ; then
fatal "You are already in backported branch $CURBRANCH. Run rpmbph in sisyphus or master branch only."
fi
echo "$CURBRANCH" > $(get_root_git_dir)/.git/.rpmbph.current
# Create branch if not exist yet
if is_exist_branch $USEBRANCH ; then
docmd git checkout $USEBRANCH || fatal "Can't checkout branch $USEBRANCH. Use $BPSPEC manually or remove it."
else
docmd git branch $USEBRANCH || fatal
fi
}
checkout_original_branch()
{
local CURBRANCH
CURBRANCH=$(cat $(get_root_git_dir)/.git/.rpmbph.current)
rm -f $(get_root_git_dir)/.git/.rpmbph.current
docmd git checkout $CURBRANCH
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment