# GERRIT_BRANCH is the _intended_ branch of the commit under review
# E.g. git push HEAD:refs/for/master => GERRIT_BRANCH='master'
-# GERRIT_TOPIC is the rest of the refspec after GERRIT_BRANCH
-refspec="$commit_hash:refs/for/$GERRIT_BRANCH/$GERRIT_TOPIC"
+# GERRIT_TOPIC is the rest of the refspec after GERRIT_BRANCH when the topic
+# is set for the change.
+if [ -z "${GERRIT_TOPIC:-}" ] ; then
+ refspec="$commit_hash:refs/for/$GERRIT_BRANCH"
+else
+ refspec="$commit_hash:refs/for/$GERRIT_BRANCH/$GERRIT_TOPIC"
+fi
echo >&2 "Pushing to OpenDev"