feat(import-packages): import all branches
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
|
||||
if [ $# -eq 0 ]
|
||||
then
|
||||
echo "$0 <repository url>..."
|
||||
@@ -10,25 +12,33 @@ fi
|
||||
#
|
||||
# For each repository:
|
||||
#
|
||||
# 1. rewrite history, moving all files into packages/<repository>
|
||||
# 2. rename all tags: <tag> → <repository>-<tag>
|
||||
# 3. merge with master
|
||||
# 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)
|
||||
[ -d "packages/$pkg" ] || { {
|
||||
[ -f ".git/refs/remotes/$pkg/master" ] || \
|
||||
git remote add "$pkg" "$url"
|
||||
} && {
|
||||
git fetch --no-tags "$pkg" master refs/tags/*:refs/tags/"$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 && \
|
||||
mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"
|
||||
' --tag-name-filter 'cat' "$pkg/master" && \
|
||||
git merge --allow-unrelated-histories "$pkg/master"
|
||||
git remote rm "$pkg"
|
||||
} }
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user