github.com/noironetworks/cilium-net@v1.6.12/contrib/backporting/start-backport (about) 1 #!/bin/bash 2 # 3 # Copyright 2019 Authors of Cilium 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 source $(dirname $(readlink -ne $BASH_SOURCE))/../release/lib/common.sh 18 source $TOOL_LIB_PATH/gitlib.sh 19 source $(dirname $(readlink -ne $BASH_SOURCE))/common.sh 20 21 # Validate command-line 22 common::argc_validate 1 23 24 BRANCH="${1:-}" 25 if [ "$BRANCH" = "" ]; then 26 BRANCH=$(git symbolic-ref --short HEAD) 27 fi 28 BRANCH=$(echo "$BRANCH" | sed 's/^v//') 29 30 # Extra optional suffix in cases where there are multiple backport PRs that 31 # have the same conflicting branch name. 32 SUFFIX="${2}" 33 34 git fetch origin 35 if ! git branch -a | grep -q "origin/v$BRANCH$" ; then 36 echo "usage: start-backport <branch version> [suffix]" 1>&2 37 echo " (detected branch $BRANCH)" 1>&2 38 common::exit 1 39 fi 40 41 DATE=$(date --rfc-3339=date) 42 PRBRANCH="pr/v${BRANCH}-backport-${DATE}${SUFFIX}" 43 44 if (git --no-pager branch | grep -q "${PRBRANCH}"); then 45 echo "Error: branch '${PRBRANCH}' already exists" 46 echo "Consider passing a suffix as the second parameter" 47 echo 48 echo "Example:" 49 echo " ./contrib/backporting/start-backport ${BRANCH} \"-2\"" 50 common::exit 1 51 fi 52 53 git checkout -b "${PRBRANCH}" origin/v$BRANCH 54 contrib/backporting/check-stable $BRANCH v$BRANCH-backport-$DATE.txt