Skip to content

Instantly share code, notes, and snippets.

@eduan
Last active May 11, 2016 14:38
Show Gist options
  • Save eduan/77137dae1bcd64f9c2d5204c3233ea4b to your computer and use it in GitHub Desktop.
Save eduan/77137dae1bcd64f9c2d5204c3233ea4b to your computer and use it in GitHub Desktop.
Magento branch switcher
#/bin/bash
if [[ "$1" == "-h" || "$1" == "-help" ]]; then
echo "Script de deploy";
echo "./deploy [dir] [branch]";
exit;
fi
if [[ "$1" == "-b" ]]; then
echo "Branch atuais:";
for D in `ls -d $2*/`
do
cd $D;
echo "$D: ";
git branch | grep "*";
cd ../;
done
exit;
fi
echo "Iniciando deploy";
if [[ -d "$1" && -d "$1/.git" ]]; then
cd $1;
git status;
read -p "Deseja eliminar alterações pendentes de commit da branch atual?[s/N]" -n 1 -r;
if [[ $REPLY =~ ^[Ss]$ ]]; then
echo;
git checkout .;
git clean -fd;
git fetch --all;
if [[ "$(git branch -a | grep $2)" ]]; then
echo "Trocando para branch: $2";
git checkout $2;
else
echo "Branch $2 inexistente";
fi
echo -e "\nBranch atual:\n";
git status;
echo "Limpando cache em var/*";
rm -rf var/cache/* var/full_page_cache/* var/session var/log/* var/report/*
fi
fi
echo "Deploy encerrado";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment