-# 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}%topic=${GERRIT_TOPIC}"
+refspec="${commit_hash}:refs/for/${GERRIT_BRANCH}"
+
+# When 'push-upstream wip' is specified the Work-In-Progress flag is set to change on push to upstream
+if [[ "${GERRIT_EVENT_TYPE:-}" == "comment-added" && "${GERRIT_EVENT_COMMENT_TEXT:-}" =~ "push-upstream wip" ]] ; then
+ wip_option="--push-option wip"
+# When 'push-upstream ready' is specified the Work-In-Progress flag from a change is removed on push to upstream
+elif [[ "${GERRIT_EVENT_TYPE:-}" == "comment-added" && "${GERRIT_EVENT_COMMENT_TEXT:-}" =~ "push-upstream ready" ]] ; then
+ wip_option="--push-option ready"
+fi
+
+# When the topic is set for a change the GERRIT_TOPIC is push upstream using git option
+if [ -n "${GERRIT_TOPIC:-}" ] ; then
+ topic_option="--push-option topic=${GERRIT_TOPIC}"