@@ -67,14 +67,25 @@ set -o errexit
6767set -o nounset
6868set -o pipefail
6969
70+ # Verify git status
71+ if git_status=$( git status --porcelain --untracked=no 2> /dev/null) && [[ -n " ${git_status} " ]]; then
72+ echo " !!! Dirty tree. Clean up and try again."
73+ exit 1
74+ fi
75+
76+ REPO_ROOT=" $( git rev-parse --show-toplevel) "
77+ declare -r REPO_ROOT
78+ cd " ${REPO_ROOT} "
79+ declare -r REBASEMAGIC=" ${REPO_ROOT} /.git/rebase-apply"
80+ if [[ -e " ${REBASEMAGIC} " ]]; then
81+ echo " !!! 'git rebase' or 'git am' in progress. Clean up and try again."
82+ exit 1
83+ fi
84+
7085# Set constants used by the client generator.
7186export USERNAME=kubernetes
7287
7388# Set up utilities.
74- repo_root=" $( git rev-parse --show-toplevel) "
75- declare -r repo_root
76- cd " ${repo_root} "
77-
7889source scripts/util/changelog.sh
7990source scripts/util/kube_changelog.sh
8091
@@ -83,6 +94,45 @@ KUBERNETES_BRANCH=${KUBERNETES_BRANCH:-$(python3 "scripts/constants.py" KUBERNET
8394CLIENT_VERSION=${CLIENT_VERSION:- $(python3 " scripts/constants.py" CLIENT_VERSION)}
8495DEVELOPMENT_STATUS=${DEVELOPMENT_STATUS:- $(python3 " scripts/constants.py" DEVELOPMENT_STATUS)}
8596
97+ # Create a local branch
98+ STARTINGBRANCH=$( git symbolic-ref --short HEAD)
99+ declare -r STARTINGBRANCH
100+ gitamcleanup=false
101+ function return_to_kansas {
102+ if [[ " ${gitamcleanup} " == " true" ]]; then
103+ echo
104+ echo " +++ Aborting in-progress git am."
105+ git am --abort > /dev/null 2>&1 || true
106+ fi
107+
108+ echo " +++ Returning you to the ${STARTINGBRANCH} branch and cleaning up."
109+ git checkout -f " ${STARTINGBRANCH} " > /dev/null 2>&1 || true
110+ }
111+ trap return_to_kansas EXIT
112+
113+ remote_branch=upstream/master
114+ if [[ $CLIENT_VERSION != * " snapshot" * ]]; then
115+ remote_branch=upstream/release-" ${CLIENT_VERSION%% .* } " .0
116+ fi
117+ echo " +++ Updating remotes..."
118+ git remote update upstream origin
119+ if ! git log -n1 --format=%H " ${remote_branch} " > /dev/null 2>&1 ; then
120+ echo " !!! '${remote_branch} ' not found."
121+ echo " (In particular, it needs to be a valid, existing remote branch that I can 'git checkout'.)"
122+ exit 1
123+ fi
124+
125+ newbranch=" $( echo " automated-release-of-${CLIENT_VERSION} -${remote_branch} " | sed ' s/\//-/g' ) "
126+ newbranchuniq=" ${newbranch} -$( date +%s) "
127+ declare -r newbranchuniq
128+ echo " +++ Creating local branch ${newbranchuniq} "
129+ git checkout -b " ${newbranchuniq} " " ${remote_branch} "
130+
131+ # If it's an actual release, pull master branch
132+ if [[ $CLIENT_VERSION != * " snapshot" * ]]; then
133+ git pull -X theirs upstream master
134+ fi
135+
86136# Get Kubernetes API versions
87137old_client_version=$( python3 " scripts/constants.py" CLIENT_VERSION)
88138old_k8s_api_version=$( util::changelog::get_k8s_api_version " v$old_client_version " )
0 commit comments