2017-10-05 09:53:36 -05:00
|
|
|
#!/bin/sh
|
|
|
|
|
2017-12-30 09:59:23 -06:00
|
|
|
set -eu
|
|
|
|
|
2017-12-12 05:08:21 -06:00
|
|
|
if [ $# -eq 0 ]
|
|
|
|
then
|
|
|
|
echo "$0 <repository url>..."
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2017-10-05 09:53:36 -05:00
|
|
|
# Import repositories into this mono-repo.
|
|
|
|
#
|
|
|
|
# For each repository:
|
|
|
|
#
|
2017-12-30 09:59:23 -06:00
|
|
|
# 1. import all branches and tags as <repository>/*
|
|
|
|
# 2. rewrite history, moving all files into packages/<repository>
|
|
|
|
# 3. merge and delete <repository>/master
|
2017-12-12 05:08:21 -06:00
|
|
|
for url
|
2017-10-05 09:53:36 -05:00
|
|
|
do
|
2017-12-12 05:08:21 -06:00
|
|
|
pkg=$(basename "$url" .git)
|
2017-12-30 09:59:23 -06:00
|
|
|
if [ -d "packages/$pkg" ]
|
|
|
|
then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
git remote add "$pkg" "$url"
|
|
|
|
git fetch --no-tags "$pkg" \
|
|
|
|
"refs/heads/*:refs/heads/$pkg/*" \
|
|
|
|
"refs/tags/*:refs/tags/$pkg/*"
|
|
|
|
git remote rm "$pkg"
|
|
|
|
|
|
|
|
git filter-branch -f --index-filter '
|
|
|
|
git ls-files -s | \
|
|
|
|
sed "s%\t\"*%&packages/'"$pkg"'/%" | \
|
|
|
|
GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
|
|
|
|
git update-index --index-info && \
|
|
|
|
if [ -f "$GIT_INDEX_FILE.new" ]; then \
|
|
|
|
mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"; \
|
|
|
|
fi
|
|
|
|
' --tag-name-filter 'cat' -- --branches="$pkg/*"
|
|
|
|
|
|
|
|
git merge --allow-unrelated-histories "$pkg/master"
|
|
|
|
git branch -d "$pkg/master"
|
2017-10-05 09:53:36 -05:00
|
|
|
done
|