Skip to content

Instantly share code, notes, and snippets.

@sembozdemir
Last active December 6, 2018 07:58
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 sembozdemir/85663f9d451cd43e2759a72a6a8b1006 to your computer and use it in GitHub Desktop.
Save sembozdemir/85663f9d451cd43e2759a72a6a8b1006 to your computer and use it in GitHub Desktop.
Gerrit push aliases for ZSH
# 1- Enable git plugin -> plugins=( git )
# 2- Add these lines in your .zshrc file
# 3- Edit your reviewers in gerrit_reviewers() function below
# 4- Run `gpr <branch_name>` to push, `gpr! <branch_name>` to push as Draft
# Aliases For gerrit
function gerrit_reviewers() {
echo "%r=a@a.com,r=b@b.com,r=c@c.com"
}
gpr() {
local reviewers=$(gerrit_reviewers)
if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then
git push origin "HEAD:refs/for/${*}${reviewers}"
else
[[ "$#" == 0 ]] && local b="$(git_current_branch)"
git push origin "HEAD:refs/for/${b:=$1}${reviewers}"
fi
}
compdef _git gpr=git-checkout
gpr!() {
local reviewers=$(gerrit_reviewers)
if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then
git push origin "HEAD:refs/drafts/${*}${reviewers}"
else
[[ "$#" == 0 ]] && local b="$(git_current_branch)"
git push origin "HEAD:refs/drafts/${b:=$1}${reviewers}"
fi
}
compdef _git gpr!=git-checkout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment