Skip to content

Instantly share code, notes, and snippets.

@flodolo
Last active January 28, 2024 08:13
Show Gist options
  • Save flodolo/a7d0ffcc4aac1bcadb93e26766e50b0b to your computer and use it in GitHub Desktop.
Save flodolo/a7d0ffcc4aac1bcadb93e26766e50b0b to your computer and use it in GitHub Desktop.
Convert l10n repos to monorepo
#! /usr/bin/env bash
# This script requires git-cinnabar and jq installed
# https://github.com/glandium/git-cinnabar
# https://jqlang.github.io/jq/download/
#
# If you pass a path to the script, it will search for locale clones in that folder.
# If that's not available, it will clone the remote repository for the locale.
clones_path=$1
function convert_repo() {
# $1: locale code
local locale="$1"
path="${clones_path}/${locale}"
if [ ! -d "${path}/.hg" ]
then
echo "Folder ${path} does not exist. Cloning remote repository"
git clone hg::https://hg.mozilla.org/l10n-central/${locale}
else
echo "Using local repository: ${path}"
git clone hg::${path}
fi
# Rename branch as main
cd $locale
git branch -m branches/default/tip main
cd ..
}
# Store absolute path where the script is located
current_dir="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
# Get a list of l10n-central locales (folders) if there isn't a list already
# saved as locales.txt
if [ ! -f "locales.txt" ]
then
curl "https://hg.mozilla.org/l10n-central/?style=json" | jq -r ".entries.[].name" > locales.txt
fi
locales_hgmo=$(cat locales.txt)
mkdir -p "$current_dir/single-locale"
cd "$current_dir/single-locale"
for locale in $locales_hgmo
do
convert_repo $locale
done
# Initialize gecko-l10n and import single-locales repositories.
cd $current_dir
git init gecko-l10n
cd gecko-l10n
touch README.md
git add . && git commit -a -m "Initialize repository"
for locale in $locales_hgmo
do
cd $current_dir/single-locale/$locale
git filter-repo --to-subdirectory-filter $locale --force
cd $current_dir/gecko-l10n
git remote add $locale $current_dir/single-locale/$locale
git fetch $locale
git merge --allow-unrelated-histories --no-commit $locale/main
git commit -a -m "Merge content from l10n-central/${locale}"
git remote remove $locale
done
cd $current_dir/gecko-l10n
git prune
git gc
# Remove .hgtags files
find . -name ".hg*" | xargs git rm $1
git commit -a -m "Remove .hg files"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment