Skip to content

Instantly share code, notes, and snippets.

@felipernb
Created October 21, 2016 13:16
Show Gist options
  • Save felipernb/968fafb2eb8f8fa741847a2eb87e62e5 to your computer and use it in GitHub Desktop.
Save felipernb/968fafb2eb8f8fa741847a2eb87e62e5 to your computer and use it in GitHub Desktop.
#!/bin/bash
function is_mac() {
if [ `uname -s` = "Darwin" ]; then
return 0
else
return 1
fi
}
ROOT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
function import_repo() {
PKG_NAME=$1
if is_mac; then
TMP_DIR=$( mktemp -d -t import-repo )
else
TMP_DIR=$( mktemp -d -t import-repo.XXXXXX )
fi
echo "Importing ${USER}/${PKG_NAME}"
git clone [email protected]:$USER/$PKG_NAME $TMP_DIR
ESCAPED_PKG_NAME=`echo ${PKG_NAME} | sed 's/\-/\\\-/g'`
cd $TMP_DIR
echo "Rewriting history for ${PKG_NAME}"
ESCAPED_PATH="packages/${ESCAPED_PKG_NAME}"
git filter-branch --prune-empty --tree-filter '
if [ ! -e '"$ESCAPED_PATH"' ]; then
mkdir -p '"$ESCAPED_PATH"'
git ls-tree --name-only $GIT_COMMIT | xargs -I files mv files '"$ESCAPED_PATH"'
fi'
if [ $? -eq 0 ]; then
cd $ROOT_DIR
git remote add -f $PKG_NAME $TMP_DIR
git merge --allow-unrelated-histories $PKG_NAME/master
git remote remove $PKG_NAME
rm -rf $TMP_DIR
else
echo "Failed to rewrite history, aborting."
exit 1
fi
}
USER="felipernb"
LIBS=("crypto debouncer linkedlist protobuf transport backoff")
for lib in $LIBS; do
import_repo $lib
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment