Skip to content

Instantly share code, notes, and snippets.

@koral--
Last active January 19, 2017 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koral--/a5b8fc725a8e44eb553f to your computer and use it in GitHub Desktop.
Save koral--/a5b8fc725a8e44eb553f to your computer and use it in GitHub Desktop.
change-merged gerrit hook pushing branches according to ${GERRIT_SITE}/etc/client_replication_remotes

Requirements

  • bash
  • git

Usage

  • create client_replication_remotes file in ${GERRIT_SITE}/etc/ (syntax in example below)
  • create change-merged file in ${GERRIT_SITE}/hooks
  • make change-merged executable (chmod +x change-merged)

Gerrit daemon restart is not needed, hook will be fired at the nearest opportunity.

Troubleshooting

git command output is stored in ${GERRIT_SITE}/logs/change-merged_log

#!/bin/bash
#The MIT License Copyright (c) 2016 Karol Wrótniak, Droids On Roids
while [[ $# > 1 ]]
do
key="$1"
case $key in
--project)
HOOK_PROJECT="$2"
shift
;;
--branch)
HOOK_BRANCH="$2"
shift
;;
*)
# unknown option
;;
esac
shift
done
while read -r remote_project remote_branch remote_url
do
if [[ ${HOOK_PROJECT} == ${remote_project} ]] && [[ ${HOOK_BRANCH} == ${remote_branch} ]]
then
cd ${GIT_DIR}
GIT_OUTPUT="$((git push ${remote_url} ${BRANCH}) 2>&1)"
if [[ $? -eq 0 ]]
then
STATUS="SUCCESS"
else
STATUS="ERROR "
fi
echo "["$(date '+%Y-%m-%d %H:%M:%S')"]" ${STATUS} ${HOOK_PROJECT} ${HOOK_BRANCH} ${GIT_OUTPUT} >> ${GERRIT_SITE}/logs/change-merged_log
fi
done < ${GERRIT_SITE}/etc/client_replication_remotes
#<project name> <source branch> <destination branch> <url>
gradle-snippets master master git@github.com:DroidsOnRoids/gradle-snippets.git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment