xref: /freebsd/tools/tools/git/ghpr/ghpr-init.sh (revision a1a06bc686615bc4ff32b553ad1193fb30406607)
1#!/bin/sh
2
3set -e
4
5die() {
6    echo $*
7    exit 1
8}
9
10# Create a fresh branch for the staging tree.
11BRANCH=${1:-staging}
12base=main
13
14if [ "$(git config branch.${BRANCH}.opabinia)" = "true" ]; then
15    echo "Branch ${BRANCH} has already been initialized"
16    # Bail if the branch already exists
17else
18    if git rev-parse --verify ${BRANCH} > /dev/null 2>&1; then
19	echo "Branch ${BRANCH} already exists, skipping creation, but rebasing to ${base}"
20	git rebase ${base} ${BRANCH}
21    else
22	# Create the branch and tag it as the one we're using for opabinia merging.
23	echo "Creating ${BRANCH} from ${base} to land changes"
24	git checkout -b ${BRANCH} ${base} || die "Can't create ${BRANCH}"
25    fi
26fi
27
28git config set --type bool --all branch.${BRANCH}.opabinia true || die "Can't annotate"
29git config set --all branch.${BRANCH}.opabinia.base "${base}" || die "Can't annotate"
30