Skip to content

Instantly share code, notes, and snippets.

@chrisl8888
Last active October 10, 2015 22:48
Show Gist options
  • Save chrisl8888/3762567 to your computer and use it in GitHub Desktop.
Save chrisl8888/3762567 to your computer and use it in GitHub Desktop.
drush gl - Use drush to git pull files from the target. Usage `drush gl @mysite.dev`
<?php
/**
* Implementation of hook_drush_command().
*/
function gl_drush_command() {
$items['git-pull'] = array(
'aliases' => array(
'gl'
),
'bootstrap' => DRUSH_BOOTSTRAP_MAX,
'description' => 'Attempts to pull the repo for the remote server.',
);
return $items;
}
function drush_gl_git_pull(){
$drupal_root = drush_get_context('DRUSH_SELECTED_DRUPAL_ROOT');
if (empty($drupal_root)) {
return drush_user_abort('The Drupal root path cannot be found, please run this command in a higher Drupal bootstrap.');
}
drush_shell_exec('cd ' . DRUPAL_ROOT);
drush_shell_exec('git status');
$output = drush_shell_exec_output();
foreach ($output as $msg) {
if (strpos($msg, 'Not a git repository') !== FALSE) {
return drush_user_abort('Aborting: The Drupal root path does not contain a valid .git repository.');
}
if (strpos($msg, 'working directory clean')) {
drush_log('Git repository is currently clean.', 'status');
}
}
drush_log('Attempting to pull the latest code...', 'status');
drush_shell_exec_interactive('git pull');
}
#/bin/bash
cd $HOME/.drush
mkdir -p $HOME/.drush/inc && cd $HOME/.drush/inc
wget https://gist.github.com/chrisjlee/3762567/raw/0dd9f49dec5790690716a3a8fac250ad928f6a36/gl.drush.inc
@chrisl8888
Copy link
Author

install:

curl https://gist.github.com/chrisjlee/3762567/raw/164787b24914f9f306e82fd804186f01506a0ece/setup-drush-gl.sh | sh

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