From d6053e931abd1bd7900b61e09c917702200636a2 Mon Sep 17 00:00:00 2001 From: Phan An Date: Thu, 31 Oct 2024 20:56:50 +0700 Subject: [PATCH] feat: ensure current branch is `master` for release --- app/Console/Commands/ReleaseCommand.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/Console/Commands/ReleaseCommand.php b/app/Console/Commands/ReleaseCommand.php index aa639a3d..adfd6b43 100644 --- a/app/Console/Commands/ReleaseCommand.php +++ b/app/Console/Commands/ReleaseCommand.php @@ -25,6 +25,7 @@ class ReleaseCommand extends Command public function handle(): int { + self::ensureMainBranch(); self::ensureCleanWorkingDirectory(); $this->getCurrentVersion(); @@ -134,6 +135,17 @@ class ReleaseCommand extends Command note('Current version: ' . $this->currentVersion->prefix()); } + private static function ensureMainBranch(): void + { + $branch = trim(Process::run('git branch --show-current')->output()); + + if ($branch !== 'master') { + error("You must be on the master branch to release a new version (Current branch: '$branch.')"); + + exit(self::FAILURE); + } + } + private static function ensureCleanWorkingDirectory(): void { if (Process::run('git status --porcelain')->output()) {