Skip to content

Instantly share code, notes, and snippets.

@seanf
Last active October 28, 2016 01:39
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 seanf/767c3218c1fb2e30c12d9c04d6564368 to your computer and use it in GitHub Desktop.
Save seanf/767c3218c1fb2e30c12d9c04d6564368 to your computer and use it in GitHub Desktop.
Merge Zanata repos
#!/bin/zsh -ex
# https://zanata.atlassian.net/browse/ZNTA-1391
# FIXME handle extra branches on client and api
# determine directory containing this script
SCRIPT_DIR=$( dirname "$0:A" )
oldParentVersion=30-SNAPSHOT
newVersion=4.0.0-SNAPSHOT
workingDir=$PWD/zanata-megamerge
mkdir $workingDir; cd $workingDir
# FIXME depth
# --depth 1
git clone git@github.com:zanata/zanata-server.git server
git clone --mirror git@github.com:zanata/zanata-client.git client
git clone --mirror git@github.com:zanata/zanata-common.git common
git clone --mirror git@github.com:zanata/zanata-api.git api
git clone --mirror git@github.com:zanata/zanata-parent.git parent
setopt extendedglob # requires zsh
others=($(echo ^server))
function gitCloneBranches() {
# http://stackoverflow.com/a/16563327/14379
git branch --all | sed -n "/\/HEAD /d; /\/master$/d; /remotes/p;" | xargs -L1 git checkout --force --track
git checkout master
}
function deletePRs() {
git for-each-ref --format="%(refname)" refs/pull/ refs/reviewable/ | xargs --no-run-if-empty -n 1 git update-ref -d
}
cd server
deletePRs
gitCloneBranches
mkdir server
git rm .travis.yml
# NB we don't want to git mv .gitignore .gitattributes .travis-settings.xml
git mv ^server server/
git commit -nm "chore(ZNTA-1391) move server to subdir; disable Travis"
# fetch+merge all branches+tags from the other repos
for d in $others; do
echo $d:
git remote add --fetch --tags $d ../$d
git checkout $d/master
git checkout -b ZNTA-1391-${d}
mkdir $d
git rm .travis*
# the glob pattern should pick up everything except $d and .git
# (#qD) extended glob qualifier tells zsh to include dot files in the glob
# NB the standard glob qualifier version ^(api|.git)(.D) negates zanata-common-api
git mv ^($d|.git)(#qD) $d/
git commit -nm "chore(ZNTA-1391) move $d to subdir; disable Travis"
git checkout master
# GIT_EDITOR=true: use default commit message
GIT_EDITOR=true git merge ZNTA-1391-${d}
git branch -d ZNTA-1391-${d}
echo
done
# grab some other branches we want to keep
# from api:
git checkout api/ZNTA-1302-legacy-via-file && git checkout -b api-ZNTA-1302-legacy-via-file
git checkout ZNTA-1333-language-react || true
git checkout restore-version-4.0.0-SNAPSHOT || true
git checkout streaming-parser || true
# from client:
git checkout client/ZNTA-1302-legacy-via-file && git checkout -b client-ZNTA-1302-legacy-via-file
git checkout java-nio-file || true
git checkout maven-plugin-annotations || true
git checkout rawToFile || true
git checkout rhbz870876 || true
git checkout zanata-console || true
#from parent:
git checkout fix-warnings || true
git checkout master
# copy root pom.xml to server dir (which will become the new root dir):
cat <<EOF > pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.zanata</groupId>
<artifactId>zanata-platform</artifactId>
<name>Zanata Platform</name>
<url>http://zanata.org/</url>
<packaging>pom</packaging>
<parent>
<groupId>org.zanata</groupId>
<artifactId>parent</artifactId>
<version>${newVersion}</version>
<relativePath>parent</relativePath>
</parent>
<modules>
<module>parent</module>
<module>api</module>
<module>common</module>
<module>client</module>
<module>server</module>
</modules>
</project>
EOF
# remove explicit version from aggregator poms
sed -i "/<version>${newVersion}<\/version>/d" */pom.xml
# rename zanata-parent to parent and point to the new parent pom
sed -i "s|<artifactId>zanata-parent</artifactId>|<artifactId>parent</artifactId>|" */pom.xml
sed -i "s|<relativePath>../zanata-parent</relativePath>|<relativePath>../parent</relativePath>|" */pom.xml
# update to match new parent's version instead of old
sed -i "s|<version>${oldParentVersion}</version>|<version>${newVersion}</version>|" */pom.xml
# check that Maven is happy
mvn -q validate
git add pom.xml */pom.xml
git commit -m "chore(ZNTA-1391) link poms to new parent pom, create root pom"
# make backup before BFG run
git clone . ../server-pre-clean
git-fix-emails
$SCRIPT_DIR/repoclean.sh
# tell zsh to stop logging every command
unsetopt -x
echo "don't forget to update the paths in .gitignore to match the new subdirectories"
echo "when you're ready:"
# need to push all refs, not just master
echo git push --all git@github.com:zanata/zanata-platform.git
echo git push --tags git@github.com:zanata/zanata-platform.git
echo "WARNING: don't push the shallow clone!"
echo the merged repo can be found here:
echo cd $workingDir/server
#!/bin/bash -e
echo Cleaning up repositories with BFG
echo Before expire/gc:
du -hs .git/
echo Running expire/gc:
git reflog expire --expire=now --all && git gc --prune=now --aggressive
echo Before cleanup:
du -hs .git/
#git-find-largest
echo Cleaning up with the BFG Repo-Cleaner:
bfg --strip-blobs-bigger-than 1M --delete-folders gwt-unitCache --delete-files '{bundle*.css,bundle.min.js,bundle.js,libs.css,libs*.js,templates*.js,*.js.map,*.pdf,*.swf,*.war}'
echo Running expire/gc:
git reflog expire --expire=now --all && git gc --prune=now --aggressive
echo After cleanup:
du -hs .git/
#git-find-largest
# remove these files if possible:
# All sizes are in kB's. The pack column is the size of the object, compressed, inside the pack file.
# size pack SHA location
# 2872 703 62b29fc833d9c5c7423ce3b9b87cf83e3c83063e zanata-adapter-glossary/src/test/resources/glossary/compendium-zh_TW.po
# 1828 471 d5ad8fd81f17c5b56dceaa9dd20f574bb6d6c5e5 zanata-war/src/main/webapp/app/bundle.js
# 1414 264 c1b1c8fcc6040bd4e3639c04967cf86c5f67c9b3 zanata-war/src/test/resources/tmx/fedora-readme-burning-isos.tmx
# 1318 179 d6a52093f3baed9d04be00ca0b8fb258c44832ad zanata-adapter-xliff/src/test/resources/StringResource_de.xml
# 428 152 46ea179a7dca791987aa40a434e720daaeef0234 zanata-war/src/main/webapp/app/js/libs.js
# 338 31 00bd1183a902602675c1ca9b7805e3d583b9ad44 client/zanata-client-commands/src/test/resources/xliffDir2/StringResource_en-GB.xml
# 334 91 749900b6d88fdc2a10eb1b9c0a153d4e38634f06 zanata-war/src/main/webapp/profile/js/bundle.min.js
# 332 95 16285a69ef38a8ba6c4e6502a29215562cb94da0 zanata-war/src/main/webapp/app/js/app.js
@seanf
Copy link
Author

seanf commented Oct 28, 2016

Note that git-fix-emails is not in this gist, because it has hard-coded email addresses in it.

git-fix-emails used git fast-export --all piped to a sed script, piped to git fast-import --force to repair a couple of damaged author/committer headers we had in the repo, plus git filter-branch --force --env-filter '{embedded script}' --tag-name-filter cat -- --branches --tags to update some other email addresses.

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