Skip to content

Commit

Permalink
[eas-cli] Remove random branch name generation for --auto branch name…
Browse files Browse the repository at this point in the history
… non-vcs fallback
  • Loading branch information
wschurman committed Dec 7, 2024
1 parent 97fe2d6 commit 96ac085
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
6 changes: 2 additions & 4 deletions packages/eas-cli/src/branch/utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { Client } from '../vcs/vcs';

export async function getDefaultBranchNameAsync(vcsClient: Client): Promise<string> {
return (
(await vcsClient.getBranchNameAsync()) || `branch-${Math.random().toString(36).substring(2, 4)}`
);
export async function getDefaultBranchNameAsync(vcsClient: Client): Promise<string | null> {
return await vcsClient.getBranchNameAsync();
}

export class BranchNotFoundError extends Error {
Expand Down
2 changes: 1 addition & 1 deletion packages/eas-cli/src/commands/branch/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}));
}
Expand Down
10 changes: 8 additions & 2 deletions packages/eas-cli/src/project/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down

0 comments on commit 96ac085

Please sign in to comment.