blob: 94b6faa7df3e03f15c45eb60e92251139d00d257 (
plain)
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
#!/bin/bash
# Variables
REPO_PATH=${1}
PULL_REMOTE=${2}
PUSH_REMOTE=${3}
BRANCH=${4}
PREFIX=${5}
REGEX=${6}
show_help() {
echo "${0} <repo path> <pull remote> <push remote> <branch> <push tag prefix> v<track regex>" >&2
echo "Example: ${0} ~/repos/kernel stable origin 3.12 kogaion- 3\.12\.[0-9999]" >&2
}
if [ ! -d "${REPO_PATH}" ]; then
show_help
exit 1
fi
if [ -z "${PULL_REMOTE}" ]; then
show_help
exit 1
fi
if [ -z "${PUSH_REMOTE}" ]; then
show_help
exit 1
fi
if [ -z "${BRANCH}" ]; then
show_help
exit 1
fi
if [ -z "${PREFIX}" ]; then
show_help
exit 1
fi
if [ -z "${REGEX}" ]; then
show_help
exit 1
fi
rollback() {
cd "${REPO_PATH}" || return 1
git rebase --abort || true
git reset --hard "${PUSH_REMOTE}/${BRANCH}" || return 1
}
start() {
cd "${REPO_PATH}" || return 1
echo "Fetching ${PULL_REMOTE}"
git fetch --quiet "${PULL_REMOTE}" || {
rollback
return 1;
}
echo "Fetching ${PUSH_REMOTE}"
git fetch --quiet "${PUSH_REMOTE}" || {
rollback
return 1;
}
local tags=$(git tag | grep -e "v${REGEX}")
echo "Tracking tags:"
echo -e "${tags}"
if [ -z "${tags}" ]; then
echo "No tags to track for: ${REGEX} in ${REPO_PATH}"
return 0
fi
local bumps=()
local tag= tracked_tag=
for tag in ${tags}; do
tracked_tag="${PREFIX}${tag/v}"
echo "Checking tag: ${tag}, ${tracked_tag}"
if ! git tag | grep -q -e "^${tracked_tag}$"; then
echo "Not tracked: ${tag}, ${tracked_tag}"
bumps+=( "${tag}" )
fi
done
if [ -z "${bumps[*]}" ]; then
echo "Nothing to do."
return 0
fi
if ! git show-branch "${BRANCH}" > /dev/null; then
echo "Creating branch: ${BRANCH}"
git checkout -q "${PUSH_REMOTE}/${BRANCH}" -b "${BRANCH}" || {
rollback
return 1;
}
else
echo "Checking out branch: ${BRANCH}"
git checkout -q "${BRANCH}" || {
rollback
return 1;
}
fi
echo "Updating branch"
git rebase --quiet "${PUSH_REMOTE}/${BRANCH}" || {
rollback
return 1;
}
for tag in "${bumps[@]}"; do
echo "Working on tag: ${tag}"
git merge --quiet "${tag}" -m "Automatic merge of tag ${PULL_REMOTE}/${tag}" || {
rollback
return 1;
}
bash kogaion/bump-configs.sh || {
rollback
return 1;
}
local changed=$(git ls-files -m -d -o --exclude-standard kogaion/config)
if [ -n "${changed}" ]; then
git commit --quiet kogaion/config -m "kogaion: bump configs" || {
rollback
return 1;
}
fi
git push --quiet || {
rollback
return 1;
}
git push --quiet --tags || {
rollback
return 1;
}
tracked_tag="${PREFIX}${tag/v}"
bash kogaion/tag-version.sh "${tracked_tag}" || {
rollback
return 1;
}
echo "Released ${tracked_tag}"
done
}
start
|