aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2021-05-15 21:33:43 +0200
committerGravatar GitHub <noreply@github.com> 2021-05-15 21:33:43 +0200
commit97ba6261a8eb7f94963ecc91043e5a2d54ffd248 (patch)
treeb58419a63e8ce687d5132a038bd7cbde5e1fa8d1
parentffb0e30dde98bcef1b3fa0bfb020c3a478c6a402 (diff)
git update auto change to edge branch (#3589)
* git update auto change to edge branch For existing installations using automatic git update, checkout *edge* branch if it was still using *master* or *dev*. * One more prune * Fix several small issues * theirs does not work here * Use migration mechanism * Better handling of Migration errors * Test details * Fix tests * Do not use new migration system for now
-rw-r--r--app/Controllers/updateController.php54
-rw-r--r--lib/Minz/Migrator.php2
-rw-r--r--lib/lib_rss.php20
-rwxr-xr-xp/i/index.php4
-rw-r--r--tests/lib/Minz/MigratorTest.php3
5 files changed, 67 insertions, 16 deletions
diff --git a/app/Controllers/updateController.php b/app/Controllers/updateController.php
index fb00165ea..2b43bc2aa 100644
--- a/app/Controllers/updateController.php
+++ b/app/Controllers/updateController.php
@@ -6,36 +6,76 @@ class FreshRSS_update_Controller extends Minz_ActionController {
return is_dir(FRESHRSS_PATH . '/.git/');
}
+ /**
+ * Automatic change to the new name of edge branch since FreshRSS 1.18.0.
+ */
+ public static function migrateToGitEdge() {
+ $errorMessage = 'Error during git checkout to edge branch. Please change branch manually!';
+
+ if (!is_writable(FRESHRSS_PATH . '/.git/')) {
+ throw new Exception($errorMessage);
+ }
+
+ exec('git branch --show-current', $output, $return);
+ if ($return != 0) {
+ throw new Exception($errorMessage);
+ }
+ $line = is_array($output) ? implode('', $output) : $output;
+ if ($line !== 'master' && $line !== 'dev') {
+ return true; // not on master or dev, nothing to do
+ }
+
+ Minz_Log::warning('Automatic migration to git edge branch');
+ unset($output);
+ exec('git checkout edge --guess -f', $output, $return);
+ if ($return != 0) {
+ throw new Exception($errorMessage);
+ }
+
+ unset($output);
+ exec('git reset --hard FETCH_HEAD', $output, $return);
+ if ($return != 0) {
+ throw new Exception($errorMessage);
+ }
+
+ return true;
+ }
+
public static function hasGitUpdate() {
$cwd = getcwd();
chdir(FRESHRSS_PATH);
$output = array();
try {
- exec('git fetch', $output, $return);
+ exec('git fetch --prune', $output, $return);
if ($return == 0) {
+ unset($output);
exec('git status -sb --porcelain remote', $output, $return);
} else {
- $line = is_array($output) ? implode('; ', $output) : '' . $output;
+ $line = is_array($output) ? implode('; ', $output) : $output;
Minz_Log::warning('git fetch warning:' . $line);
}
} catch (Exception $e) {
Minz_Log::warning('git fetch error:' . $e->getMessage());
}
chdir($cwd);
- $line = is_array($output) ? implode('; ', $output) : '' . $output;
- return strpos($line, '[behind') !== false || strpos($line, '[ahead') !== false;
+ $line = is_array($output) ? implode('; ', $output) : $output;
+ return $line == '' ||
+ strpos($line, '[behind') !== false || strpos($line, '[ahead') !== false || strpos($line, '[gone') !== false;
}
public static function gitPull() {
$cwd = getcwd();
chdir(FRESHRSS_PATH);
- $output = '';
+ $output = [];
$return = 1;
try {
- exec('git fetch', $output, $return);
+ exec('git fetch --prune', $output, $return);
if ($return == 0) {
+ unset($output);
exec('git reset --hard FETCH_HEAD', $output, $return);
}
+
+ self::migrateToGitEdge();
} catch (Exception $e) {
Minz_Log::warning('Git error:' . $e->getMessage());
if ($output == '') {
@@ -44,7 +84,7 @@ class FreshRSS_update_Controller extends Minz_ActionController {
$return = 1;
}
chdir($cwd);
- $line = is_array($output) ? implode('; ', $output) : '' . $output;
+ $line = is_array($output) ? implode('; ', $output) : $output;
return $return == 0 ? true : 'Git error: ' . $line;
}
diff --git a/lib/Minz/Migrator.php b/lib/Minz/Migrator.php
index f6e9f8298..eac1bac5b 100644
--- a/lib/Minz/Migrator.php
+++ b/lib/Minz/Migrator.php
@@ -103,7 +103,7 @@ class Minz_Migrator
if (!$migrator->upToDate()) {
// still not up to date? It means last migration failed.
- return 'A migration failed to be applied, please see previous logs';
+ return trim('A migration failed to be applied, please see previous logs.' . "\n" . implode("\n", $results));
}
return true;
diff --git a/lib/lib_rss.php b/lib/lib_rss.php
index 3cacc8390..602576256 100644
--- a/lib/lib_rss.php
+++ b/lib/lib_rss.php
@@ -548,15 +548,25 @@ function getNonStandardShortcuts($shortcuts) {
}
function errorMessage($errorTitle, $error = '') {
- // Prevent empty <h2> tags by checking if error isn't empty first
- if ('' !== $error) {
+ $errorTitle = htmlspecialchars($errorTitle, ENT_NOQUOTES, 'UTF-8');
+
+ $message = '';
+ $details = '';
+ // Prevent empty tags by checking if error isn not empty first
+ if ($error) {
$error = htmlspecialchars($error, ENT_NOQUOTES, 'UTF-8');
- $error = "<h2>{$error}</h2>";
+
+ // First line is the main message, other lines are the details
+ list($message, $details) = explode("\n", $error, 2);
+
+ $message = "<h2>{$message}</h2>";
+ $details = "<pre>{$details}</pre>";
}
- $errorTitle = htmlspecialchars($errorTitle, ENT_NOQUOTES, 'UTF-8');
+
return <<<MSG
<h1>{$errorTitle}</h1>
- {$error}
+ {$message}
+ {$details}
<h2>Check the logs</h2>
<p>FreshRSS logs are located in <code>./FreshRSS/data/users/*/log*.txt</code></p>
<p><em>N.B.:</em> A typical problem is wrong file permissions in the <code>./FreshRSS/data/</code> folder
diff --git a/p/i/index.php b/p/i/index.php
index 3591c4446..71b19a1ca 100755
--- a/p/i/index.php
+++ b/p/i/index.php
@@ -63,8 +63,8 @@ if (!file_exists($applied_migrations_path)) {
}
if ($error) {
- Minz_Log::error($error);
- errorMessage('Fatal error');
syslog(LOG_INFO, 'FreshRSS Fatal error! ' . $error);
+ Minz_Log::error($error);
+ die(errorMessage('Fatal error', $error));
}
}
diff --git a/tests/lib/Minz/MigratorTest.php b/tests/lib/Minz/MigratorTest.php
index d4b1e030c..dec1d0176 100644
--- a/tests/lib/Minz/MigratorTest.php
+++ b/tests/lib/Minz/MigratorTest.php
@@ -310,9 +310,10 @@ class MigratorTest extends TestCase
public function testExecuteFailsIfAMigrationIsFailing() {
$migrations_path = TESTS_PATH . '/fixtures/migrations_with_failing/';
$applied_migrations_path = tempnam('/tmp', 'applied_migrations.txt');
- $expected_result = 'A migration failed to be applied, please see previous logs';
+ $expected_result = 'A migration failed to be applied, please see previous logs.';
$result = Minz_Migrator::execute($migrations_path, $applied_migrations_path);
+ list($result, ) = explode("\n", $result, 2);
$this->assertSame($expected_result, $result);
$versions = file_get_contents($applied_migrations_path);