Skip to content

Instantly share code, notes, and snippets.

@cboden
Forked from clue/gist:4212c21860f4078a89dc
Last active August 29, 2015 14:01
Show Gist options
  • Save cboden/ce4870f324ae4a83dcf3 to your computer and use it in GitHub Desktop.
Save cboden/ce4870f324ae4a83dcf3 to your computer and use it in GitHub Desktop.
#!/bin/bash
SCRIPT=$(pwd)/$(dirname $0)/filter-repo.sh
$SCRIPT "event-loop" EventLoop
$SCRIPT stream Stream
$SCRIPT cache Cache
$SCRIPT dns Dns
$SCRIPT http Http
$SCRIPT "http-client" HttpClient
$SCRIPT socket Socket
$SCRIPT "socket-client" SocketClient
GIT_REPO=$1
COMPONENT=$2
GIT_REMOTE='[email protected]:cboden'
git clone "$GIT_REMOTE"/react.git $GIT_REPO
cd $GIT_REPO
# list all branches that should be preserved
# only version branches listed, as to skip WIP branches
git branch 0.3 origin/0.3
git branch 0.4 origin/0.4
#master is already included (default from clone)
# remove reference from origin to speed up rewriting its references
git remote remove origin
# now rewrite the whole history by moving src/React/* to src/*
# this will allow us to extract the contents in a consistent directory structure
git filter-branch --index-filter \
'git ls-files -s | sed "s/src\/React/src/" |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
git update-index --index-info &&
mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' -- --all
# remove backup references automatically created by git-filter-branch
rm -r .git/refs/original/
# now that everything is always located in src/$COMPONENT we can easily extract its sole history
git filter-branch --subdirectory-filter src/"$COMPONENT"/ -- --all
# remove backup references automatically created by git-filter-branch
rm -r .git/refs/original/
# Done already! :)
# Final steps:
git push --all "$GIT_REMOTE"/"$GIT_REPO".git --force
git push --tags "$GIT_REMOTE"/"$GIT_REPO".git --force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment