Skip to content

Instantly share code, notes, and snippets.

@thcipriani thcipriani/GerritAccountstoLower.org Secret
Last active Aug 28, 2019

Embed
What would you like to do?
gerrit accounts
#!/bin/bash
set -euo pipefail
USERNAME="$1"
USERNAME_LOWER="${USERNAME,,}"
SHASUM=$(printf "gerrit:%s" "${USERNAME_LOWER}" | shasum -a 1)
NEW_FILE=$(printf '%s/%s\n' "${SHASUM:0:2}" "${SHASUM:2:38}")
OLD_FILE=$(git grep --full-name --files-with-matches "gerrit:${USERNAME}")
git mv "$OLD_FILE" "$NEW_FILE"
# Change username to lowercase in new file
sed -i "s/gerrit:${USERNAME}/gerrit:${USERNAME_LOWER}/" "$NEW_FILE"

Gerrit Accounts

Prep patch on your local machine

Adding a file for “gerrit:User” all lowercase

cd /srv/Projects/Wikimedia/All-Users
git fetch origin refs/meta/external-ids:refs/meta/external-ids
git checkout FETCH_HEAD
gerrit-username-to-lowercase.sh "Username"
git commit -m 'thcipriani: add gerrit:Username'
git format-patch HEAD^
scp xxx.patch  cobalt.wikimedia.org:/tmp/xxx.patch

SU to gerrit2 on cobalt

sudo su - gerrit2

Backup All-Users.git on cobalt

cp -r /srv/gerrit/git/All-Users.git /srv/gerrit/All-Users-$(date -I).git

Clone All-Users repo on cobalt

git clone /srv/gerrit/git/All-Users.git All-Users

Fetch down refs meta on coalt

cd All-Users
git fetch origin refs/meta/external-ids:refs/meta/external-ids
git checkout FETCH_HEAD

Apply patch and push on cobalt

git apply --check --3way xxx.patch
git am --3way xxx.patch
git push origin HEAD:refs/meta/external-ids

Reindex accounts on your local machine

ssh -p 29418 gerrit.wikimedia.org -- gerrit index start accounts --force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.