1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash
# 2003-2010, 2012, 2015, 2017 (c) Etersoft www.etersoft.ru
# Author: Vitaly Lipatov <lav@etersoft.ru>
# Public domain
# used: BINARYREPO MDISTR
# set: USEBRANCH OLDBRANCH
set_usebranch()
{
#local OLDBRANCH
#[ -f "$LISTNAMES" ] || fatal "Run with one spec inside gear repo"
USEBRANCH=$BINARYREPO
[ -n "$USEBRANCH" ] || return 1
[ "$USEBRANCH" = "$(get_altdistr_mod "$DISTRVERSION")" ] && return 1
# TODO: drop support of the legacy
# 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
return 0
}
# used: USEBRANCH OLDBRANCH BPSPEC
# set: CURBRANCH
set_currentbranch()
{
CURBRANCH=$(get_current_branch)
local cb
cb=$(cat $(get_root_git_dir)/.git/.rpmbph.current 2>/dev/null)
if [ -n "$cb" ] ; then
echog "Autorestore from broken build..."
docmd git checkout $cb || fatal
CURBRANCH=$cb
rm -fv $(get_root_git_dir)/.git/.rpmbph.current
#rm -fv $BPSPEC $BPSPEC.*
[ -n "$BPSPEC" ] && rm -fv $BPSPEC.*
fi
if [ "$CURBRANCH" = "$USEBRANCH" ] || [ "$CURBRANCH" = "$OLDBRANCH" ] ; then
fatal "You are already in backported branch $CURBRANCH. Run rpmbph in sisyphus or master branch only."
fi
}
# used: USEBRANCH
checkout_bpbranch()
{
# TODO
[ -n "$CURBRANCH" ] || fatal "use assert in checkout_bpbranch"
echo "$CURBRANCH" > $(get_root_git_dir)/.git/.rpmbph.current
local PGEAR="gear"
# 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."
if ! git branch -a | grep -q "remotes/$PGEAR/" ; then
docmd gremote $GIRARHOST -o
docmd git fetch $PGEAR $USEBRANCH
fi
# if we successful with gear
if git branch -a | grep -q "remotes/$PGEAR/$USEBRANCH" ; then
docmd git fetch $PGEAR $USEBRANCH
docmd git merge --ff-only $PGEAR/$USEBRANCH || fatal
fi
else
info "Creating branch $USEBRANCH..."
if ! git branch -a | grep -q "remotes/$PGEAR/$USEBRANCH" ; then
# if we have no fetched branch
docmd gremote $GIRARHOST -o
docmd git fetch $PGEAR $USEBRANCH
fi
# if we successful with gear
if git branch -a | grep -q "remotes/$PGEAR/$USEBRANCH" ; then
docmd git fetch $PGEAR $USEBRANCH
docmd git checkout -b $USEBRANCH $PGEAR/$USEBRANCH || fatal
else
docmd git checkout -b $USEBRANCH || fatal
fi
fi
}
# used: USEBRNACH
# set: CURBRANCH
checkout_usebranch()
{
CURBRANCH=$(get_current_branch)
if [ "$USEBRANCH" = "$CURBRANCH" ] ; then
# let's think we called from rpmbph
return
fi
checkout_bpbranch
}
checkout_original_branch()
{
local CURBRANCH
CURBRANCH=$(cat $(get_root_git_dir)/.git/.rpmbph.current 2>/dev/null)
[ -z "$CURBRANCH" ] && return
rm -f $(get_root_git_dir)/.git/.rpmbph.current
docmd git checkout $CURBRANCH
}