From cbe8ab3d38bd7051cca1ed0cf8df0ff1d1497cff Mon Sep 17 00:00:00 2001 From: Arnold Roa Date: Sun, 18 Oct 2015 15:01:39 -0500 Subject: [PATCH 1/3] Added option to log full output of git pull command --- deploy-config.php | 1 + inc/class.deploy.php | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/deploy-config.php b/deploy-config.php index 5a149d6..1d87a88 100644 --- a/deploy-config.php +++ b/deploy-config.php @@ -40,6 +40,7 @@ * Sets the deploy log directory */ define( 'DEPLOY_LOG_DIR', dirname( __FILE__ ) ); +define( 'DEPLOY_FULL_OUTPUT', true ); /* Do not edit below this line */ require_once 'inc/class.deploy.php'; diff --git a/inc/class.deploy.php b/inc/class.deploy.php index ac122d2..7705e40 100644 --- a/inc/class.deploy.php +++ b/inc/class.deploy.php @@ -210,7 +210,7 @@ private function execute() { exec( 'git reset --hard HEAD', $output ); // Update the local repository - exec( 'git pull ' . $this->_remote . ' ' . $this->_branch, $output ); + exec( 'git pull ' . $this->_remote . ' ' . $this->_branch . ' 2>&1', $output, $return_var ); // Secure the .git directory echo exec( 'chmod -R og-rx .git' ); @@ -218,8 +218,12 @@ private function execute() { if ( is_callable( $this->_post_deploy ) ) call_user_func( $this->_post_deploy ); - $this->log( '[SHA: ' . $this->_commit . '] Deployment of ' . $this->_name . ' from branch ' . $this->_branch . ' successful' ); - echo( '[SHA: ' . $this->_commit . '] Deployment of ' . $this->_name . ' from branch ' . $this->_branch . ' successful' ); + $log_msg = "[SHA: {$this->_commit} Deployment of {$this->_name} from branch {$this->_branch} successful". + $this->log( $log_msg ); + echo $log_msg; + + if (DEPLOY_FULL_OUTPUT) + $this->log( $output ); } catch ( Exception $e ) { $this->log( $e, 'ERROR' ); } From 51a7c0faa3893234564b11d02bde0a453190d8df Mon Sep 17 00:00:00 2001 From: Arnold Roa Date: Sun, 18 Oct 2015 15:02:11 -0500 Subject: [PATCH 2/3] thrown an error if there is some error on git pull --- inc/class.deploy.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/inc/class.deploy.php b/inc/class.deploy.php index 7705e40..d00e231 100644 --- a/inc/class.deploy.php +++ b/inc/class.deploy.php @@ -212,6 +212,9 @@ private function execute() { // Update the local repository exec( 'git pull ' . $this->_remote . ' ' . $this->_branch . ' 2>&1', $output, $return_var ); + if ($return_var != 0) + throw new Exception("Git pull failed", 1); + // Secure the .git directory echo exec( 'chmod -R og-rx .git' ); @@ -224,8 +227,10 @@ private function execute() { if (DEPLOY_FULL_OUTPUT) $this->log( $output ); + } catch ( Exception $e ) { $this->log( $e, 'ERROR' ); + $this->log( $output ); } } } From 8db4246ecacae4e2be743adf147dd1d39e7e08c9 Mon Sep 17 00:00:00 2001 From: Arnold Roa Date: Sun, 18 Oct 2015 15:03:08 -0500 Subject: [PATCH 3/3] Added instructions to fix github issues when working with private repos --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index ee6e7c3..f5fd687 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,21 @@ More: https://confluence.atlassian.com/pages/viewpage.action?pageId=271943168 ## Usage * commit and push +## Common Issues + +### Not able to pull from a private github repository +In order to be able to pull from a github repository, this script has to connect using a public key, you have to add the key to the .ssh folder of the user who is running the git-deploy script. And server has to trust on github authenticity without interactive prompt, you can fix this creating a .php file with this content and running only once, you should see a succesfully authentication message with some debug information. + +```php +error_reporting(E_ALL); +header('Content-type: text/plain'); +ini_set('display_errors',1); +ini_set('display_startup_errors',1); +echo system( 'ssh -v -o "StrictHostKeyChecking no" git@github.com 2>&1' ); +// Uncomment this lines to also check that pull is working +//chdir('/path/to/repository/'); +//echo system('git pull origin master 2>&1'); // change master for your branch if needed +``` # More information http://lkwdwrd.com/git-auto-deployment/