refactor: getCurrentBranch respects main (#29369)

This commit is contained in:
Jeremy Rose 2021-05-27 17:32:16 -07:00 коммит произвёл GitHub
Родитель f3dff819fc
Коммит f664f37793
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 5 добавлений и 2 удалений

Просмотреть файл

@ -6,6 +6,9 @@ const ELECTRON_DIR = path.resolve(__dirname, '..', '..');
const SRC_DIR = path.resolve(ELECTRON_DIR, '..');
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');
const pass = '✓'.green;
@ -73,7 +76,7 @@ async function handleGitCall (args, gitDir) {
async function getCurrentBranch (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 branches = (await handleGitCall([
'branch',
@ -82,7 +85,7 @@ async function getCurrentBranch (gitDir) {
'--remote'
], 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) {
console.log(`${fail} no release branch exists for this ref`);
process.exit(1);