-
-
Save robskillington/066314c16976e3ff117e8fb4442bd448 to your computer and use it in GitHub Desktop.
Merging m3db/* repos into m3db/m3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
usage() { | |
echo "usage: $0 <repo> <name>" | |
echo | |
echo "<repo>" | |
echo " The repo link, e.g. https://github.com/m3db/m3coordinator.git" | |
echo | |
echo "<name>" | |
echo " The name of the directory within 'src/', conventionally the repo name with the 'm3' prefix stripped, e.g. coordinator" | |
} | |
if [[ $# -ne 2 ]]; then | |
usage | |
exit 1 | |
fi | |
# git clone repo, e.g. https://github.com/m3db/m3coordinator.git | |
repo="$1" | |
# Name of the directory within src/, conventionally the repo name with the | |
# m3 prefix stripped, e.g. coordinator | |
name="$2" | |
oldname="$(echo "$repo" | sed 's#^.*/\([a-zA-Z0-9]*\).*#\1#')" | |
folder="src/$name" | |
monobranch="monorepo-merge-$name" | |
mkdir -p "$folder" | |
git remote add "$name" "$repo" | |
echo "Fetching '$name/master'..." | |
# Complains about no common commits, which is expected | |
git fetch -q "$name" master 2> /dev/null | |
# Hack to rewrite history to prepend $folder/ to all files | |
echo "Rewriting history to change directory structure..." | |
# NOTE for debugging: there is a tab character in the sed. Not all versions | |
# of sed interpret \t as a tab character. | |
git filter-branch -f --index-filter \ | |
'git ls-files -s | sed "s% \"*%&'"$folder"'/%" | | |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info && | |
mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' "$name/master" | |
echo "Checking out branch '$monobranch'" | |
# Complains about non-empty .ci/ directory (submodule), but it's okay because | |
# we don't do modifications to it. | |
git checkout -q --no-track -b "$monobranch" "$name/master" 2> /dev/null | |
echo "Rebasing on 'master'..." | |
# Complains about non-empty .ci/ directory (submodule), but it's okay because | |
# we don't do modifications to it. | |
git rebase -q --committer-date-is-author-date master 2> /dev/null | |
# Clean up remote | |
git remote remove "$name" | |
echo "Cleaning up submodules..." | |
rm -rf "$folder/.ci" "$folder/.gitmodules" ".git/modules/$folder/.ci" | |
git rm -q --cached "$folder/.ci" | |
echo "Replacing 'github.com/m3db/$oldname' with 'github.com/m3db/m3/src/$name'.." | |
find . -name "*.go" -exec sed -i '' -e "s#github.com/m3db/$oldname#github.com/m3db/m3/src/$name#g" '{}' \; | |
echo "Done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment