-git checkout -b "${BRANCH,,}" "origin/${BRANCH,,}"
-git submodule foreach git checkout -b "${BRANCH,,}" "origin/${BRANCH,,}"
+pip install --user --quiet --upgrade git-review
+
+# 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
+
+# Setup Gerrit remote to ensure Change-Id gets set on commit.
+git config --global --add gitreview.username "jenkins-$SILO"
+git review -s
+git remote -v
+git submodule foreach "git review -s"