From e023809c8ca035787617b69a2f8ae7c277d7dca3 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Sat, 30 Dec 2017 16:59:23 +0100 Subject: [PATCH] feat(import-packages): import all branches --- scripts/import-packages | 46 +++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/scripts/import-packages b/scripts/import-packages index c15dec391..132f93767 100755 --- a/scripts/import-packages +++ b/scripts/import-packages @@ -1,5 +1,7 @@ #!/bin/sh +set -eu + if [ $# -eq 0 ] then echo "$0 ..." @@ -10,25 +12,33 @@ fi # # For each repository: # -# 1. rewrite history, moving all files into packages/ -# 2. rename all tags: - -# 3. merge with master +# 1. import all branches and tags as /* +# 2. rewrite history, moving all files into packages/ +# 3. merge and delete /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