1 # shellcheck shell=bash
3 BASE_BRANCHES
="stable testing devel"
5 if [[ ! -o errexit
]] ||
[[ ! -o nounset
]]; then
6 echo "This library is meant to be used with 'set -e' and 'set -u'. Exiting..." >&2
10 # Returns "" if in detached head
11 git_current_branch
() {
13 if git_ref
="$(git symbolic-ref HEAD 2>/dev/null)"; then
14 echo "${git_ref#refs/heads/}"
20 git_in_detached_head
() {
21 [ -z "$(git_current_branch)" ]
24 # Returns "" if ref does not exist
25 git_commit_from_ref
() {
26 git rev-parse
--verify "${@}" 2>/dev
/null ||
:
29 # shellcheck disable=SC2120
30 git_current_commit
() {
31 git_commit_from_ref
"${@}" HEAD
34 # Returns "" if not a tag
35 git_tag_from_commit
() {
36 git describe
--tags --exact-match "${1}" 2>/dev
/null ||
:
39 # Returns "" if not on a tag
41 git_tag_from_commit
"$(git_current_commit)"
44 # Try to describe what currently is checked out. Returns "" if we are
45 # in detached HEAD, otherwise, in order, the tag pointing to HEAD, or
47 git_current_head_name
() {
49 ret
="$(git_current_tag)"
50 if [ -z "${ret}" ]; then
51 ret
="$(git_current_branch)"
57 [ -n "$(git_current_tag)" ]
60 git_only_doc_changes_since
() {
61 local commit non_doc_diff
62 commit
="$(git_commit_from_ref "${1}")"
63 non_doc_diff
="$(git diff \
72 [ -z "${non_doc_diff}" ]
76 head -n1 config
/base_branch
80 # shellcheck disable=SC2086
85 for base_branch
in $BASE_BRANCHES ; do
86 if [ "$(git_current_branch)" = "${base_branch}" ] ; then
94 # Returns the top commit ref of the base branch
95 git_base_branch_head
() {
96 git_commit_from_ref
"${@}" origin
/"$(base_branch)"
99 branch_name_to_suite
() {
102 echo "$branch" |
sed -e 's,[^.a-z0-9-],-,ig' |
tr '[:upper:]' '[:lower:]'
113 test -n "$(git tag -l "$tag")"
116 version_was_released
() {
119 version
="$(echo "$version" | tr '~' '-')"
120 git_tag_exists
"$version"
123 version_in_changelog
() {
124 dpkg-parsechangelog |
awk '/^Version: / { print $2 }'
127 previous_version_in_changelog
() {
128 dpkg-parsechangelog
--offset 1 --count 1 |
awk '/^Version: / { print $2 }'
131 # Make it so that when this script is called, any function defined in
132 # this script can be invoked via arguments, e.g.:
134 # $ auto/scripts/utils.sh git_commit_from_ref 3.0-beta2
135 # eca83a88a9dd958b16b4d5b04fea3ea503a3815d
137 if grep -q __utils_sh_magic_5773fa52-0d1a-11e7-a606-0021ccc177a7
"${0}" && [ -n "${1}" ]; then
138 if grep -q "^${1}() {$" "${0}"; then
141 echo "unknown shell function: ${1}" >&2