Use git reset --hard instead of git pull to refresh local files

Better error reporting
This commit is contained in:
Damian Mooyman 2016-06-27 19:37:34 +12:00
parent 055888bf71
commit 2c8cba75be
1 changed files with 11 additions and 8 deletions

View File

@ -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;