Skip to content

Commit

Permalink
Better git error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Alkarex committed May 25, 2024
1 parent b7cc814 commit 02942f4
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions app/Controllers/updateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,28 @@ public static function isGit(): bool {
}

/**
* Automatic change to the new name of edge branch since FreshRSS 1.18.0.
* Automatic change to the new name of edge branch since FreshRSS 1.18.0,
* and perform checks for several git errors.
* @throws Minz_Exception
*/
public static function migrateToGitEdge(): bool {
$errorMessage = 'Error during git checkout to edge branch. Please change branch manually!';

if (!is_writable(FRESHRSS_PATH . '/.git/config')) {
throw new Minz_Exception($errorMessage);
throw new Minz_Exception('Error during git checkout: .git directory does not seem writeable! ' .
'Please git pull manually!');
}

exec('which git', $output, $return);
if ($return != 0) {
throw new Minz_Exception("Error {$return} git not found: Please update manually!");
}

//Note `git branch --show-current` requires git 2.22+
exec('git symbolic-ref --short HEAD', $output, $return);
exec('git symbolic-ref --short HEAD 2>&1', $output, $return);
if ($return != 0) {
throw new Minz_Exception($errorMessage);
throw new Minz_Exception("Error {$return} during git symbolic-ref: " .
'Reapply `chown www-data:www-data -R ' . FRESHRSS_PATH . '` ' .
'or git pull manually! ' .
json_encode($output, JSON_UNESCAPED_SLASHES));
}
$line = implode('', $output);
if ($line !== 'master' && $line !== 'dev') {
Expand All @@ -34,13 +42,14 @@ public static function migrateToGitEdge(): bool {
unset($output);
exec('git checkout edge --guess -f', $output, $return);
if ($return != 0) {
throw new Minz_Exception($errorMessage);
throw new Minz_Exception("Error {$return} during git checkout to edge branch! ' .
'Please change branch manually!");
}

unset($output);
exec('git reset --hard FETCH_HEAD', $output, $return);
if ($return != 0) {
throw new Minz_Exception($errorMessage);
throw new Minz_Exception("Error {$return} during git reset! Please git pull manually!");
}

return true;
Expand Down Expand Up @@ -142,7 +151,7 @@ public function indexAction(): void {
if ($version == '') {
$version = 'unknown';
}
if (touch(FRESHRSS_PATH . '/index.html')) {
if (@touch(FRESHRSS_PATH . '/index.html')) {
$this->view->update_to_apply = true;
$this->view->message = [
'status' => 'good',
Expand Down

0 comments on commit 02942f4

Please sign in to comment.