Skip to content

Commit

Permalink
Avoid git rebase conflicts during development on other branches (#1071)
Browse files Browse the repository at this point in the history
Co-authored-by: ildyria <beviguier@gmail.com>
  • Loading branch information
nagmat84 and ildyria authored Aug 1, 2021
1 parent bc918a3 commit 65383e4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 31 deletions.
19 changes: 12 additions & 7 deletions app/Actions/Update/Apply.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Actions\Update;

use App\Metadata\GitHubFunctions;
use App\Metadata\LycheeVersion;
use App\Models\Configs;
use App\Models\Logs;
Expand All @@ -10,18 +11,19 @@

class Apply
{
/**
* @var LycheeVersion
*/
private $lycheeVersion;
private LycheeVersion $lycheeVersion;
private GitHubFunctions $githubFunctions;

/**
* @param LycheeVersion $lycheeVersion
* @param LycheeVersion $lycheeVersion
* @param GitHubFunctions $githubFunctions
*/
public function __construct(
LycheeVersion $lycheeVersion
LycheeVersion $lycheeVersion,
GitHubFunctions $githubFunctions
) {
$this->lycheeVersion = $lycheeVersion;
$this->githubFunctions = $githubFunctions;
}

/**
Expand Down Expand Up @@ -135,7 +137,10 @@ public function filter(array &$output)
public function run()
{
$output = [];
if ($this->check_prod_env_allow_migration($output)) {
if (
$this->githubFunctions->is_master_branch() &&
$this->check_prod_env_allow_migration($output)
) {
$this->lycheeVersion->isRelease or $this->git_pull($output);
$this->artisan($output);
$this->lycheeVersion->isRelease or $this->call_composer($output);
Expand Down
44 changes: 20 additions & 24 deletions app/Metadata/GitHubFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Metadata;

use App;
use App\Exceptions\NotInCacheException;
use App\Exceptions\NotMasterException;
use App\Facades\Helpers;
Expand All @@ -13,20 +12,11 @@

class GitHubFunctions
{
/**
* @var string
*/
public $head;
public string $head;

/**
* @var string
*/
public $branch;
public string $branch;

/**
* @var GitRequest
*/
private $gitRequest;
private GitRequest $gitRequest;

/**
* Base constructor.
Expand Down Expand Up @@ -55,24 +45,19 @@ public function __construct(GitRequest $gitRequest)
*
* @return string
*/
private function trim($commit_id)
private function trim($commit_id): string
{
return trim(substr($commit_id, 0, 7));
}

/**
* look at .git/HEAD and return the current branch.
* Return false if the file is not readable.
* Return master if it is CI.
*
* @return false|string
*/
public function get_current_branch()
{
if (App::runningUnitTests()) {
return 'master';
}

// @codeCoverageIgnoreStart
$head_file = base_path('.git/HEAD');
$branch_ = file_get_contents($head_file);
Expand Down Expand Up @@ -154,7 +139,7 @@ public function count_behind(bool $cached = true)
* @return string
*/
// @codeCoverageIgnoreStart
public function get_github_head()
public function get_github_head(): string
{
try {
$commits = $this->get_commits();
Expand All @@ -174,7 +159,7 @@ public function get_github_head()
*
* @return string
*/
public function get_behind_text()
public function get_behind_text(): string
{
try {
$count = $this->count_behind(); // NotInCache or NotMaster
Expand Down Expand Up @@ -211,7 +196,7 @@ public function get_behind_text()
* @throws NotMasterException
* @throws NotInCacheException
*/
public function is_up_to_date(bool $cached = true)
public function is_up_to_date(bool $cached = true): bool
{
$count = $this->count_behind($cached);
if ($count === 0) {
Expand All @@ -228,7 +213,7 @@ public function is_up_to_date(bool $cached = true)
*
* @return bool
*/
public function has_permissions()
public function has_permissions(): bool
{
if (!$this->branch) {
// @codeCoverageIgnoreStart
Expand All @@ -244,7 +229,7 @@ public function has_permissions()
*
* @param $return
*/
public function checkUpdates(&$return)
public function checkUpdates(&$return): void
{
// add a setting to do this check only once per day ?
if (Configs::get_value('check_for_updates', '0') == '1') {
Expand All @@ -259,4 +244,15 @@ public function checkUpdates(&$return)
}
}
}

/**
* Return true if the current branch is master.
* This is used to avoid running git pulls on development branches during tests.
*
* @return bool
*/
public function is_master_branch(): bool
{
return $this->branch === 'master';
}
}

0 comments on commit 65383e4

Please sign in to comment.