Przeglądaj źródła

Better git error messages (#6496)

* Better git error messages
fix https://github.com/FreshRSS/FreshRSS/discussions/5174
fix https://github.com/FreshRSS/FreshRSS/issues/6483

* Avoid dependency on `which`
Alexandre Alapetite 1 rok temu
rodzic
commit
7593e0815b
1 zmienionych plików z 18 dodań i 9 usunięć
  1. 18 9
      app/Controllers/updateController.php

+ 18 - 9
app/Controllers/updateController.php

@@ -10,20 +10,28 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController {
 	}
 	}
 
 
 	/**
 	/**
-	 * 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
 	 * @throws Minz_Exception
 	 */
 	 */
 	public static function migrateToGitEdge(): bool {
 	public static function migrateToGitEdge(): bool {
-		$errorMessage = 'Error during git checkout to edge branch. Please change branch manually!';
-
 		if (!is_writable(FRESHRSS_PATH . '/.git/config')) {
 		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('git -v', $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+
 		//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) {
 		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);
 		$line = implode('', $output);
 		if ($line !== 'master' && $line !== 'dev') {
 		if ($line !== 'master' && $line !== 'dev') {
@@ -34,13 +42,14 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController {
 		unset($output);
 		unset($output);
 		exec('git checkout edge --guess -f', $output, $return);
 		exec('git checkout edge --guess -f', $output, $return);
 		if ($return != 0) {
 		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);
 		unset($output);
 		exec('git reset --hard FETCH_HEAD', $output, $return);
 		exec('git reset --hard FETCH_HEAD', $output, $return);
 		if ($return != 0) {
 		if ($return != 0) {
-			throw new Minz_Exception($errorMessage);
+			throw new Minz_Exception("Error {$return} during git reset! Please git pull manually!");
 		}
 		}
 
 
 		return true;
 		return true;
@@ -142,7 +151,7 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController {
 			if ($version == '') {
 			if ($version == '') {
 				$version = 'unknown';
 				$version = 'unknown';
 			}
 			}
-			if (touch(FRESHRSS_PATH . '/index.html')) {
+			if (@touch(FRESHRSS_PATH . '/index.html')) {
 				$this->view->update_to_apply = true;
 				$this->view->update_to_apply = true;
 				$this->view->message = [
 				$this->view->message = [
 					'status' => 'good',
 					'status' => 'good',