From 2c8cba75be0bc4337145afaf1fcfb36f9488547d Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Mon, 27 Jun 2016 19:37:34 +1200 Subject: [PATCH] Use git reset --hard instead of git pull to refresh local files Better error reporting --- app/code/updaters/GitMarkdownUpdater.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/code/updaters/GitMarkdownUpdater.php b/app/code/updaters/GitMarkdownUpdater.php index 3817bbb..55c0eb9 100644 --- a/app/code/updaters/GitMarkdownUpdater.php +++ b/app/code/updaters/GitMarkdownUpdater.php @@ -28,20 +28,20 @@ class GitMarkdownUpdater implements MarkdownUpdater */ protected function doFetch($path, $branch) { $errors = array(); - $checkoutCommand = sprintf( - 'cd %s && git checkout %s', + $fetchCommand = sprintf( + 'cd %s && git fetch origin %s', escapeshellarg($path), escapeshellarg($branch) ); - $pullCommand = sprintf( - 'cd %s && git pull origin %s', + $resetCommand = sprintf( + 'cd %s && git reset --hard origin/%s', escapeshellarg($path), escapeshellarg($branch) ); // Run - if($this->runCommand($checkoutCommand, $errors)) { - $this->runCommand($pullCommand, $errors); + if($this->runCommand($fetchCommand, $errors)) { + $this->runCommand($resetCommand, $errors); } return $errors; } @@ -73,9 +73,12 @@ class GitMarkdownUpdater implements MarkdownUpdater * @return bool Flag if the command was successful */ protected function runCommand($cmd, &$errors = array()) { - exec($cmd, $output, $result); + exec("{$cmd} 2>&1 >/dev/null", $output, $result); if($result) { - $errors[] = "Error running command {$cmd}"; + $errors[] = "Error running command {$cmd}:"; + foreach($output as $error) { + $errors[] = ' * ' . $error; + } return false; } return true;