Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Sets up Drupal 7 local and remote feature branch.
# Sets up a local Drupal 7 environment for working on a feature branch.
# @author Justin Endler
echo -e "\nThis script is D7-specific."
# get info
echo -e "\nFeature Branch name:"
read feature_branch_name
echo -e "\nParent Directory:"
read parent_dir
echo -e "\nMy Fork:"
read my_fork
echo -e "\nForked-from Repo:"
read forked_from_repo
# create database
# @todo add error handling for when mysql is not running
echo -e "\nCreate db..."
touch ~/create_feature_db.mysql
createdbstatement="CREATE DATABASE \`$feature_branch_name\`;"
echo "$createdbstatement" > ~/create_feature_db.mysql
/Applications/MAMP/Library/bin/mysql -p -u root < ~/create_feature_db.mysql
# import database
echo -e "\nImport db..."
echo -e "\nEnter the mysql dump backup path:"
read db_dump_path
/Applications/MAMP/Library/bin/mysql -p -u root $feature_branch_name < $db_dump_path
# get the repo code
echo -e "\nCloning develop branch..."
cd $parent_dir
git clone -b develop $my_fork $feature_branch_name
cd $feature_branch_name
echo -e "\nGet submodules..."
git submodule init
git submodule update
# again in case of time out on first
git submodule update
# merge with forked-from
echo -e "\nAttempting merge with forked-from repo..."
git remote add forkedFrom $forked_from_repo
git fetch forkedFrom
git merge forkedFrom/develop
# update remote develop
git push origin develop
# create local branch
echo -e "\nCreate local branch..."
git checkout -b $feature_branch_name
# create remote branch
echo -e "\nCreate remote branch..."
git push origin $feature_branch_name
# write database settings to settings.php
# $databases['default']['default'] = array(
# 'driver' => 'mysql',
# 'database' => $feature_branch_name,
# 'username' => 'root',
# 'password' => 'root',
# 'host' => 'localhost',
# 'prefix' => ''
# );
echo "\nWrite db config to settings.php..."
cd sites/default
touch settings.php
curl "$defaultsettings" > settings.php
echo "\$databases['default']['default'] = array('driver' => 'mysql','database' => '$feature_branch_name','username' => 'root','password' => 'root','host' => 'localhost','prefix' => '');" >> settings.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.