From c277e15141b99cdcb392f4a32126757d58b44423 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 2 Nov 2019 13:38:04 +0100 Subject: Git fetch+reset instead of clean+fetch+merge (#2625) Fix https://github.com/FreshRSS/FreshRSS/issues/2619 Avoid potentially dangerous git clean, and use more robust fetch + reset strategy instead --- app/Controllers/updateController.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'app/Controllers/updateController.php') diff --git a/app/Controllers/updateController.php b/app/Controllers/updateController.php index ebe5e4cc8..cc3aef9fd 100644 --- a/app/Controllers/updateController.php +++ b/app/Controllers/updateController.php @@ -29,20 +29,22 @@ class FreshRSS_update_Controller extends Minz_ActionController { public static function gitPull() { $cwd = getcwd(); chdir(FRESHRSS_PATH); - $output = array(); + $output = ''; $return = 1; try { - exec('git clean -f -d -f', $output, $return); + exec('git fetch', $output, $return); if ($return == 0) { - exec('git pull --ff-only', $output, $return); - } else { - $line = is_array($output) ? implode('; ', $output) : '' . $output; - Minz_Log::warning('git clean warning:' . $line); + exec('git reset --hard FETCH_HEAD', $output, $return); } } catch (Exception $e) { - Minz_Log::warning('git pull error:' . $e->getMessage()); + Minz_Log::warning('Git error:' . $e->getMessage()); + if ($output == '') { + $output = $e->getMessage(); + } + $return = 1; } chdir($cwd); + deleteInstall(); $line = is_array($output) ? implode('; ', $output) : '' . $output; return $return == 0 ? true : 'Git error: ' . $line; } @@ -52,6 +54,8 @@ class FreshRSS_update_Controller extends Minz_ActionController { Minz_Error::error(403); } + include_once(LIB_PATH . '/lib_install.php'); + invalidateHttpCache(); $this->view->update_to_apply = false; -- cgit v1.2.3 From 2495172a05725684fa4db2ed3417461d386c5cbf Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 4 Nov 2019 18:05:20 +0100 Subject: Better git fetch (#2626) Related to https://github.com/FreshRSS/FreshRSS/pull/2625 If for some reasons branches have diverged:, e.g.: ``` $ git status -sb --porcelain remote ## dev...origin/dev [ahead 4, behind 1] ``` --- app/Controllers/updateController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/Controllers/updateController.php') diff --git a/app/Controllers/updateController.php b/app/Controllers/updateController.php index cc3aef9fd..c0c1ef1c8 100644 --- a/app/Controllers/updateController.php +++ b/app/Controllers/updateController.php @@ -23,7 +23,7 @@ class FreshRSS_update_Controller extends Minz_ActionController { } chdir($cwd); $line = is_array($output) ? implode('; ', $output) : '' . $output; - return strpos($line, '[behind') !== false; + return strpos($line, '[behind') !== false || strpos($line, '[ahead') !== false; } public static function gitPull() { -- cgit v1.2.3