Skip to content

Instantly share code, notes, and snippets.

@crmorford
Last active September 8, 2017 00:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crmorford/3374db38d906eba6d74cfa226d5ab07f to your computer and use it in GitHub Desktop.
Save crmorford/3374db38d906eba6d74cfa226d5ab07f to your computer and use it in GitHub Desktop.
split branch into assets and app-deploy
#!/bin/bash
BRANCH=$1
git_stuff() {
asset_type=$1
array=$2
git checkout master
echo "creating new branch for $asset_type files"
git checkout -b $BRANCH-$asset_type
echo -e "\e[93m branch $BRANCH-$asset_type \e[0m"
echo -e "\e[35m $array \e[0m"
git checkout origin/$BRANCH "--" $array
git commit -m "$asset_type files from branch $BRANCH" --no-verify
}
echo -e "this script is a WIP. Your branch must be pushed to origin, and any \e[35mbranches called $BRANCH-media and $BRANCH-non-media will be deleted\e[0m if they exist"
echo -e "\e[35mDO YOU UNDERSTAND and accept risk \e[93m[y/n] \e[0m"
read -r -p "" response
case "$response" in
[yY][eE][sS]|[yY])
;;
*)
echo "ok bye"
exit 1
;;
esac
if [ "$BRANCH" != "" ]; then
cd ~/analytics
echo "splitting branch:" $BRANCH
declare -a CHANGED_FILES
declare -a MEDIA_FILES
declare -a NON_MEDIA_FILES
git checkout master
git branch -D $BRANCH-media $BRANCH-non-media
git fetch
git reset --hard origin/master
readarray CHANGED_FILES < <(git diff --name-only origin/$BRANCH $(git merge-base origin/$BRANCH origin/master))
echo -e "\e[35m"
for file in "${CHANGED_FILES[@]}"; do
echo $file
if [[ $file =~ ^media/ ]]; then
MEDIA_FILES+=($file)
else
NON_MEDIA_FILES+=($file)
fi
done
echo -e "\e[0m"
if (( ${#MEDIA_FILES[@]} > 0 )); then
git_stuff media ${MEDIA_FILES[*]}
fi
if (( ${#NON_MEDIA_FILES[@]} > 0 )); then
git_stuff non-media ${MEDIA_FILES[*]}
fi
else
echo -e "\e[35mYou must provide a branch name\e[0m usage is \e[93m./branch-splitter.sh branch-name\e[0m"
fi
@crmorford
Copy link
Author

crmorford commented Sep 8, 2017

L47 is the rule that is splitting the PR into 2 pieces. can be changed pretty easy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment