#!/usr/bin/env bash

set -e
set -x

CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD`

function split()
{
#    split_new_repo $1 $2


    SHA1=`./bin/splitsh-lite-arm --prefix=$1`
    git push $2 "$SHA1:$CURRENT_BRANCH"

    # Use this to split a new branch
    #git push $2 "$SHA1:refs/heads/$CURRENT_BRANCH"
}

function split_new_repo()
{
    TMP_DIR="/tmp/enqueue-repo"
    REMOTE_URL=`git remote get-url $2`

    rm -rf $TMP_DIR;
    mkdir $TMP_DIR;

    (
        cd $TMP_DIR;
        git clone $REMOTE_URL .;
        git checkout -b master;
        touch foo;
        git add foo;
        git commit -m "foo";
        git push origin master;
    );

    SHA1=`./bin/splitsh-lite-arm --prefix=$1`
    git fetch $2
    git push $2 "$SHA1:$CURRENT_BRANCH" -f
}


function remote()
{
    git remote add $1 $2 || true
}

remote resource git@github.com:CoreShop/Resource.git
remote registry git@github.com:CoreShop/Registry.git
remote address git@github.com:CoreShop/Address.git
remote configuration git@github.com:CoreShop/Configuration.git
remote core git@github.com:CoreShop/Core.git
remote currency git@github.com:CoreShop/Currency.git
remote customer git@github.com:CoreShop/Customer.git
remote index git@github.com:CoreShop/Index.git
remote locale git@github.com:CoreShop/Locale.git
remote notification git@github.com:CoreShop/Notification.git
remote order git@github.com:CoreShop/Order.git
remote payment git@github.com:CoreShop/Payment.git
remote product git@github.com:CoreShop/Product.git
remote rule git@github.com:CoreShop/Rule.git
remote sequence git@github.com:CoreShop/Sequence.git
remote shipping git@github.com:CoreShop/Shipping.git
remote store git@github.com:CoreShop/Store.git
remote taxation git@github.com:CoreShop/Taxation.git
remote pimcore git@github.com:CoreShop/Pimcore.git
remote storage-list git@github.com:CoreShop/StorageList.git
remote inventory git@github.com:CoreShop/Inventory.git
remote seo git@github.com:CoreShop/SEO.git
remote tracking git@github.com:CoreShop/Tracking.git
remote product-quantity-price-rules git@github.com:CoreShop/ProductQuantityPriceRules.git
remote user git@github.com:CoreShop/User.git
remote payum-payment git@github.com:CoreShop/PayumPayment.git
remote variant git@github.com:CoreShop/Variant.git
remote wishlist git@github.com:CoreShop/Wishlist.git

remote address-bundle git@github.com:CoreShop/AddressBundle.git
remote configuration-bundle git@github.com:CoreShop/ConfigurationBundle.git
remote core-bundle git@github.com:CoreShop/CoreBundle.git
remote currency-bundle git@github.com:CoreShop/CurrencyBundle.git
remote customer-bundle git@github.com:CoreShop/CustomerBundle.git
remote frontend-bundle git@github.com:CoreShop/FrontendBundle.git
remote index-bundle git@github.com:CoreShop/IndexBundle.git
remote locale-bundle git@github.com:CoreShop/LocaleBundle.git
remote money-bundle git@github.com:CoreShop/MoneyBundle.git
remote notification-bundle git@github.com:CoreShop/NotificationBundle.git
remote order-bundle git@github.com:CoreShop/OrderBundle.git
remote payment-bundle git@github.com:CoreShop/PaymentBundle.git
remote payum-bundle git@github.com:CoreShop/PayumBundle.git
remote product-bundle git@github.com:CoreShop/ProductBundle.git
remote resource-bundle git@github.com:CoreShop/ResourceBundle.git
remote rule-bundle git@github.com:CoreShop/RuleBundle.git
remote sequence-bundle git@github.com:CoreShop/SequenceBundle.git
remote shipping-bundle git@github.com:CoreShop/ShippingBundle.git
remote store-bundle git@github.com:CoreShop/StoreBundle.git
remote taxation-bundle git@github.com:CoreShop/TaxationBundle.git
remote tracking-bundle git@github.com:CoreShop/TrackingBundle.git
remote inventory-bundle git@github.com:CoreShop/InventoryBundle.git
remote workflow-bundle git@github.com:CoreShop/WorkflowBundle.git
remote seo-bundle git@github.com:CoreShop/SEOBundle.git
remote pimcore-bundle git@github.com:CoreShop/PimcoreBundle.git
remote theme-bundle git@github.com:CoreShop/ThemeBundle.git
remote product-quantity-price-rules-bundle git@github.com:CoreShop/ProductQuantityPriceRulesBundle.git
remote menu-bundle git@github.com:CoreShop/MenuBundle.git
remote payum-payment-bundle git@github.com:CoreShop/PayumPaymentBundle.git
remote user-bundle git@github.com:CoreShop/UserBundle.git
remote optimistic-entity-lock-bundle git@github.com:CoreShop/OptimisticEntityLockBundle.git
remote variant-bundle git@github.com:CoreShop/VariantBundle.git
remote storage-list-bundle git@github.com:CoreShop/StorageListBundle.git
remote wishlist-bundle git@github.com:CoreShop/WishlistBundle.git
<<<<<<< HEAD
remote test-bundle git@github.com:CoreShop/TestBundle.git
=======
remote messenger-bundle git@github.com:CoreShop/MessengerBundle.git
remote class-definition-patch-bundle git@github.com:CoreShop/ClassDefinitionPatchBundle.git
>>>>>>> 4.0

split 'src/CoreShop/Component/Resource' resource
split 'src/CoreShop/Component/Registry' registry
split 'src/CoreShop/Component/Address' address
split 'src/CoreShop/Component/Configuration' configuration
split 'src/CoreShop/Component/Core' core
split 'src/CoreShop/Component/Currency' currency
split 'src/CoreShop/Component/Customer' customer
split 'src/CoreShop/Component/Index' index
split 'src/CoreShop/Component/Locale' locale
split 'src/CoreShop/Component/Notification' notification
split 'src/CoreShop/Component/Order' order
split 'src/CoreShop/Component/Payment' payment
split 'src/CoreShop/Component/Product' product
split 'src/CoreShop/Component/Rule' rule
split 'src/CoreShop/Component/Sequence' sequence
split 'src/CoreShop/Component/Shipping' shipping
split 'src/CoreShop/Component/Store' store
split 'src/CoreShop/Component/Taxation' taxation
split 'src/CoreShop/Component/Pimcore' pimcore
split 'src/CoreShop/Component/StorageList' storage-list
split 'src/CoreShop/Component/Inventory' inventory
split 'src/CoreShop/Component/SEO' seo
split 'src/CoreShop/Component/Tracking' tracking
split 'src/CoreShop/Component/ProductQuantityPriceRules' product-quantity-price-rules
split 'src/CoreShop/Component/User' user
split 'src/CoreShop/Component/PayumPayment' payum-payment
split 'src/CoreShop/Component/Variant' variant
split 'src/CoreShop/Component/Wishlist' wishlist

split 'src/CoreShop/Bundle/AddressBundle' address-bundle
split 'src/CoreShop/Bundle/ConfigurationBundle' configuration-bundle
split 'src/CoreShop/Bundle/CoreBundle' core-bundle
split 'src/CoreShop/Bundle/CurrencyBundle' currency-bundle
split 'src/CoreShop/Bundle/CustomerBundle' customer-bundle
split 'src/CoreShop/Bundle/FrontendBundle' frontend-bundle
split 'src/CoreShop/Bundle/IndexBundle' index-bundle
split 'src/CoreShop/Bundle/LocaleBundle' locale-bundle
split 'src/CoreShop/Bundle/MoneyBundle' money-bundle
split 'src/CoreShop/Bundle/NotificationBundle' notification-bundle
split 'src/CoreShop/Bundle/OrderBundle' order-bundle
split 'src/CoreShop/Bundle/PaymentBundle' payment-bundle
split 'src/CoreShop/Bundle/PayumBundle' payum-bundle
split 'src/CoreShop/Bundle/ProductBundle' product-bundle
split 'src/CoreShop/Bundle/ResourceBundle' resource-bundle
split 'src/CoreShop/Bundle/RuleBundle' rule-bundle
split 'src/CoreShop/Bundle/SequenceBundle' sequence-bundle
split 'src/CoreShop/Bundle/ShippingBundle' shipping-bundle
split 'src/CoreShop/Bundle/StoreBundle' store-bundle
split 'src/CoreShop/Bundle/TaxationBundle' taxation-bundle
split 'src/CoreShop/Bundle/TrackingBundle' tracking-bundle
split 'src/CoreShop/Bundle/InventoryBundle' inventory-bundle
split 'src/CoreShop/Bundle/WorkflowBundle' workflow-bundle
split 'src/CoreShop/Bundle/SEOBundle' seo-bundle
split 'src/CoreShop/Bundle/PimcoreBundle' pimcore-bundle
split 'src/CoreShop/Bundle/ThemeBundle' theme-bundle
split 'src/CoreShop/Bundle/ProductQuantityPriceRulesBundle' product-quantity-price-rules-bundle
split 'src/CoreShop/Bundle/MenuBundle' menu-bundle
split 'src/CoreShop/Bundle/UserBundle' user-bundle
split 'src/CoreShop/Bundle/PayumPaymentBundle' payum-payment-bundle
split 'src/CoreShop/Bundle/OptimisticEntityLockBundle' optimistic-entity-lock-bundle
split 'src/CoreShop/Bundle/VariantBundle' variant-bundle
split 'src/CoreShop/Bundle/StorageListBundle' storage-list-bundle
split 'src/CoreShop/Bundle/WishlistBundle' wishlist-bundle
split 'src/CoreShop/Bundle/TestBundle' test-bundle
split 'src/CoreShop/Bundle/MessengerBundle' messenger-bundle
split 'src/CoreShop/Bundle/ClassDefinitionPatchBundle' class-definition-patch-bundle
