From 96ac085cca3037eb4860c38a8599181e8214c5aa Mon Sep 17 00:00:00 2001 From: Will Schurman Date: Fri, 6 Dec 2024 16:20:30 -0800 Subject: [PATCH] [eas-cli] Remove random branch name generation for --auto branch name non-vcs fallback --- packages/eas-cli/src/branch/utils.ts | 6 ++---- packages/eas-cli/src/commands/branch/create.ts | 2 +- packages/eas-cli/src/project/publish.ts | 10 ++++++++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/eas-cli/src/branch/utils.ts b/packages/eas-cli/src/branch/utils.ts index d9affe89f9..c6cd03720c 100644 --- a/packages/eas-cli/src/branch/utils.ts +++ b/packages/eas-cli/src/branch/utils.ts @@ -1,9 +1,7 @@ import { Client } from '../vcs/vcs'; -export async function getDefaultBranchNameAsync(vcsClient: Client): Promise { - return ( - (await vcsClient.getBranchNameAsync()) || `branch-${Math.random().toString(36).substring(2, 4)}` - ); +export async function getDefaultBranchNameAsync(vcsClient: Client): Promise { + return await vcsClient.getBranchNameAsync(); } export class BranchNotFoundError extends Error { diff --git a/packages/eas-cli/src/commands/branch/create.ts b/packages/eas-cli/src/commands/branch/create.ts index e865d22617..c523c273f0 100644 --- a/packages/eas-cli/src/commands/branch/create.ts +++ b/packages/eas-cli/src/commands/branch/create.ts @@ -58,7 +58,7 @@ export default class BranchCreate extends EasCommand { type: 'text', name: 'name', message: 'Provide a branch name:', - initial: await getDefaultBranchNameAsync(vcsClient), + initial: (await getDefaultBranchNameAsync(vcsClient)) ?? undefined, validate: value => (value ? true : validationMessage), })); } diff --git a/packages/eas-cli/src/project/publish.ts b/packages/eas-cli/src/project/publish.ts index 707251c834..0c9db8bf19 100644 --- a/packages/eas-cli/src/project/publish.ts +++ b/packages/eas-cli/src/project/publish.ts @@ -634,7 +634,13 @@ export async function getBranchNameForCommandAsync({ } if (autoFlag) { - return await getDefaultBranchNameAsync(vcsClient); + const defaultBranchNameFromVcs = await getDefaultBranchNameAsync(vcsClient); + if (!defaultBranchNameFromVcs) { + throw new Error( + 'Must supply --branch or --channel for branch name as auto-detection of branch name via --auto is not supported when no VCS is present.' + ); + } + return defaultBranchNameFromVcs; } else if (nonInteractive) { throw new Error('Must supply --channel, --branch or --auto when in non-interactive mode.'); } else { @@ -658,7 +664,7 @@ export async function getBranchNameForCommandAsync({ type: 'text', name: 'name', message: 'No branches found. Provide a branch name:', - initial: await getDefaultBranchNameAsync(vcsClient), + initial: (await getDefaultBranchNameAsync(vcsClient)) ?? undefined, validate: value => (value ? true : 'Branch name may not be empty.'), }); branchName = name;