Skip to content

Instantly share code, notes, and snippets.



Last active Jun 12, 2017
What would you like to do?
# This script will submit all pending commits to gerrit and will automatically
# add reviewers to the associated change. Reviewers can be added by simply
# listing them after greview. You can either enter their full email addresses
# or just partially enter a unique combination of letters that will be
# fuzy-matched to either the email or the name of the commiters.
# Usage: greview <reviewer-1> <reviewer-2> ...
function list_reviewers {
git log --format="%aE %aN" -n 1000 | sort | uniq
default_branch=$(cat .gitreview | grep -e 'defaultbranch' | cut -d '=' -f2)
topic_branch=$(git rev-parse --abbrev-ref HEAD)
if [ "$topic_branch" != "$default_branch" ]; then
url=$(git remote show -n gerrit |
grep Fetch |
cut -d ':' -f2- |
sed -e 's/ //g')
for rev in $reviewers
pattern="$(echo "$rev" | sed 's/\(.\)/[^ ]*\1/g')"
matches="$(list_reviewers | grep "$pattern" | cut -d ' ' -f1)"
all_reviewers=$(echo $matches | sed -e "s/ .*//g")
if [ "$all_reviewers" = "" ]; then
reviewer_opts="$reviewer_opts --reviewer $all_reviewers"
git push --receive-pack="git-receive-pack $reviewer_opts" "$url" "$push_ref"

This comment has been minimized.

Copy link

@Lekensteyn Lekensteyn commented Oct 10, 2015

I think that the last lines (git config and git push) can be simplified to avoid a new remote:

git push --receivepack="git-receive-pack $reviewer_opts" "$url" "$push_ref"

Simplification of matches that is also case sensitive now:

pattern="$(echo "$rev" | sed 's/./[^ ]*./')"
matches="$(list_reviewers | grep "$pattern" | cut -d ' ' -f1)

... now I also see that this script retrieves all authors from the commit log as reviewers which could a bit slow for large repos.


This comment has been minimized.

Copy link
Owner Author

@andersonvom andersonvom commented Nov 3, 2015

Thanks for the tips! The sed expression needed a bit of change to work properly, but it's working great now. I'm also limiting the number of commits to 1000 so that there's no performance hit in large repos. =D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment