Git - validate branch name before creation (#245029)

* Git - validate branch name before creation

* Git - tweak validation message

---------

Co-authored-by: Бацев Никита Александрович <NABatsev@sberbank.ru>
Co-authored-by: Ladislau Szomoru <3372902+lszomoru@users.noreply.github.com>
This commit is contained in:
batsev
2025-04-01 21:30:32 +03:00
committed by GitHub
parent ff63d3b488
commit 28b51a4dda

View File

@@ -2867,6 +2867,7 @@ export class CommandCenter {
const branchWhitespaceChar = config.get<string>('branchWhitespaceChar')!;
const branchValidationRegex = config.get<string>('branchValidationRegex')!;
const branchRandomNameEnabled = config.get<boolean>('branchRandomName.enable', false);
const refs = await repository.getRefs({ pattern: 'refs/heads' });
if (defaultName) {
return sanitizeBranchName(defaultName, branchWhitespaceChar);
@@ -2884,6 +2885,13 @@ export class CommandCenter {
const getValidationMessage = (name: string): string | InputBoxValidationMessage | undefined => {
const validateName = new RegExp(branchValidationRegex);
const sanitizedName = sanitizeBranchName(name, branchWhitespaceChar);
// Check if branch name already exists
const existingBranch = refs.find(ref => ref.name === sanitizedName);
if (existingBranch) {
return l10n.t('Branch "{0}" already exists', sanitizedName);
}
if (validateName.test(sanitizedName)) {
// If the sanitized name that we will use is different than what is
// in the input box, show an info message to the user informing them