-# Setup Gerrit remove to ensure Change-Id gets set on commit.
-git config --global --add gitreview.username "jenkins-releng"
+lf-activate-venv --python python3 "git-review==2.3.1"
+
+# Fail if branch cutting is not on master
+if [ "$BRANCH_CUT" = "true" ] && [ "$BRANCH" != "master" ]; then
+ echo "ERROR: Cannot branch cut on $BRANCH, its required to be on the master branch."
+ exit 1
+fi
+
+if [ "$BRANCH_CUT" = "false" ]; then
+ git checkout -b "${BRANCH,,}" "origin/${BRANCH,,}"
+
+ for module in $(git submodule | awk '{ print $2 }')
+ do
+ pushd "$module"
+ git checkout -b "${BRANCH,,}" "origin/${BRANCH,,}"
+ popd
+ done
+fi
+
+# Workaround for git-review failing to copy the commit-msg hook to submodules
+git config core.hooksPath "$(git rev-parse --show-toplevel)/.git/hooks"
+
+# Setup Gerrit remote to ensure Change-Id gets set on commit.
+git config --global --add gitreview.username "jenkins-$SILO"