refactor: getCurrentBranch respects main (#29369)
This commit is contained in:
parent
f3dff819fc
commit
f664f37793
1 changed files with 5 additions and 2 deletions
|
@ -6,6 +6,9 @@ const ELECTRON_DIR = path.resolve(__dirname, '..', '..');
|
||||||
const SRC_DIR = path.resolve(ELECTRON_DIR, '..');
|
const SRC_DIR = path.resolve(ELECTRON_DIR, '..');
|
||||||
|
|
||||||
const RELEASE_BRANCH_PATTERN = /(\d)+-(?:(?:[0-9]+-x$)|(?:x+-y$))/;
|
const RELEASE_BRANCH_PATTERN = /(\d)+-(?:(?:[0-9]+-x$)|(?:x+-y$))/;
|
||||||
|
// TODO(main-migration): Simplify once main branch is renamed
|
||||||
|
const MAIN_BRANCH_PATTERN = /^(main|master)$/;
|
||||||
|
const ORIGIN_MAIN_BRANCH_PATTERN = /^origin\/(main|master)$/;
|
||||||
|
|
||||||
require('colors');
|
require('colors');
|
||||||
const pass = '✓'.green;
|
const pass = '✓'.green;
|
||||||
|
@ -73,7 +76,7 @@ async function handleGitCall (args, gitDir) {
|
||||||
|
|
||||||
async function getCurrentBranch (gitDir) {
|
async function getCurrentBranch (gitDir) {
|
||||||
let branch = await handleGitCall(['rev-parse', '--abbrev-ref', 'HEAD'], gitDir);
|
let branch = await handleGitCall(['rev-parse', '--abbrev-ref', 'HEAD'], gitDir);
|
||||||
if (branch !== 'master' && !RELEASE_BRANCH_PATTERN.test(branch)) {
|
if (!MAIN_BRANCH_PATTERN.test(branch) && !RELEASE_BRANCH_PATTERN.test(branch)) {
|
||||||
const lastCommit = await handleGitCall(['rev-parse', 'HEAD'], gitDir);
|
const lastCommit = await handleGitCall(['rev-parse', 'HEAD'], gitDir);
|
||||||
const branches = (await handleGitCall([
|
const branches = (await handleGitCall([
|
||||||
'branch',
|
'branch',
|
||||||
|
@ -82,7 +85,7 @@ async function getCurrentBranch (gitDir) {
|
||||||
'--remote'
|
'--remote'
|
||||||
], gitDir)).split('\n');
|
], gitDir)).split('\n');
|
||||||
|
|
||||||
branch = branches.filter(b => b.trim() === 'master' || b.trim() === 'origin/master' || RELEASE_BRANCH_PATTERN.test(b.trim()))[0];
|
branch = branches.find(b => MAIN_BRANCH_PATTERN.test(b.trim()) || ORIGIN_MAIN_BRANCH_PATTERN.test(b.trim()) || RELEASE_BRANCH_PATTERN.test(b.trim()));
|
||||||
if (!branch) {
|
if (!branch) {
|
||||||
console.log(`${fail} no release branch exists for this ref`);
|
console.log(`${fail} no release branch exists for this ref`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
|
Loading…
Reference in a new issue