Skip to content

Instantly share code, notes, and snippets.

@aminin
Last active March 16, 2018 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aminin/a2ef094b3d69b8906053068eb18173bf to your computer and use it in GitHub Desktop.
Save aminin/a2ef094b3d69b8906053068eb18173bf to your computer and use it in GitHub Desktop.
Split project with multiple composer packages into subtrees
#!/usr/bin/env bash
# Search composer packages in SRC_PATH
# and split them into subtrees
#
# examples:
# bash subtree-split.sh
# SRC_PATH=bundles bash subtree-split.sh
#
# see:
# https://github.com/splitsh/lite
Color_Off='\033[0m' # Text Reset
Black='\033[0;30m' # Black
Red='\033[0;31m' # Red
Green='\033[0;32m' # Green
Yellow='\033[0;33m' # Yellow
BYellow='\033[1;33m' # Yellow Bold
Blue='\033[0;34m' # Blue
Purple='\033[0;35m' # Purple
Cyan='\033[0;36m' # Cyan
White='\033[0;37m' # White
if [[ "$SRC_PATH" == "" ]]; then
SRC_PATH=src
fi
function branchify {
echo $(sed -e 's/\([A-Z]\)/-\l\1/g' -e "s/$SRC_PATH//g" -e 's/[\/]//g' -e 's/^-\([a-z]\)/\1/g' <<< "$1");
}
function run_with_echo {
echo -e "${Purple}$1${Color_Off}"
eval "$1"
}
PREFIXES=$(ls $SRC_PATH/*/*/composer.json | sed -e "s/$SRC_PATH\/\([A-Za-z]\+\)\/\([A-Za-z0-9]\+\)\/.\+/$SRC_PATH\/\1\/\2/g");
for PREFIX in $PREFIXES; do
BRANCH=$(branchify $PREFIX);
echo -e "\n${Yellow}Splitting ${BYellow}$PREFIX ${Yellow}into branch ${BYellow}$BRANCH${Color_Off}\n"
echo -e "${Purple}splitsh-lite --prefix=$PREFIX --progress${Color_Off}"
HASH=$(splitsh-lite --prefix=$PREFIX --progress)
echo -e "${Cyan}Splitted hash $HASH${Color_Off}"
run_with_echo "git branch $BRANCH $HASH"
run_with_echo "git push git@github.com:omlook/$BRANCH.git $BRANCH:master"
run_with_echo "git br -D $BRANCH"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment