xen-orchestra/scripts/import-packages

45 lines
1012 B
Plaintext
Raw Normal View History

#!/bin/sh
set -eu
if [ $# -eq 0 ]
then
echo "$0 <repository url>..."
exit
fi
# Import repositories into this mono-repo.
#
# For each repository:
#
# 1. import all branches and tags as <repository>/*
# 2. rewrite history, moving all files into packages/<repository>
# 3. merge and delete <repository>/master
for url
do
pkg=$(basename "$url" .git)
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"
done