mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-28 12:33:35 +01:00
Git - add setting to control default branch name (#181884)
* Initial implementation * Refactor based on discussions * More pull request feedback
This commit is contained in:
@@ -307,6 +307,10 @@ function getCheckoutProcessor(repository: Repository, type: string): CheckoutPro
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function sanitizeBranchName(name: string, whitespaceChar: string): string {
|
||||
return name.trim().replace(/^-+/, '').replace(/^\.|\/\.|\.\.|~|\^|:|\/$|\.lock$|\.lock\/|\\|\*|\s|^\s*$|\.$|\[|\]$/g, whitespaceChar);
|
||||
}
|
||||
|
||||
function sanitizeRemoteName(name: string) {
|
||||
name = name.trim();
|
||||
return name && name.replace(/^\.|\/\.|\.\.|~|\^|:|\/$|\.lock$|\.lock\/|\\|\*|\s|^\s*$|\.$|\[|\]$/g, '-');
|
||||
@@ -772,7 +776,11 @@ export class CommandCenter {
|
||||
}
|
||||
}
|
||||
|
||||
await this.git.init(repositoryPath);
|
||||
const config = workspace.getConfiguration('git');
|
||||
const defaultBranchName = config.get<string>('defaultBranchName', 'main');
|
||||
const branchWhitespaceChar = config.get<string>('branchWhitespaceChar', '-');
|
||||
|
||||
await this.git.init(repositoryPath, { defaultBranch: sanitizeBranchName(defaultBranchName, branchWhitespaceChar) });
|
||||
|
||||
let message = l10n.t('Would you like to open the initialized repository?');
|
||||
const open = l10n.t('Open');
|
||||
@@ -2179,9 +2187,6 @@ export class CommandCenter {
|
||||
const branchPrefix = config.get<string>('branchPrefix')!;
|
||||
const branchWhitespaceChar = config.get<string>('branchWhitespaceChar')!;
|
||||
const branchValidationRegex = config.get<string>('branchValidationRegex')!;
|
||||
const sanitize = (name: string) => name ?
|
||||
name.trim().replace(/^-+/, '').replace(/^\.|\/\.|\.\.|~|\^|:|\/$|\.lock$|\.lock\/|\\|\*|\s|^\s*$|\.$|\[|\]$/g, branchWhitespaceChar)
|
||||
: name;
|
||||
|
||||
let rawBranchName = defaultName;
|
||||
|
||||
@@ -2206,7 +2211,7 @@ export class CommandCenter {
|
||||
ignoreFocusOut: true,
|
||||
validateInput: (name: string) => {
|
||||
const validateName = new RegExp(branchValidationRegex);
|
||||
const sanitizedName = sanitize(name);
|
||||
const sanitizedName = sanitizeBranchName(name, branchWhitespaceChar);
|
||||
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
|
||||
@@ -2224,7 +2229,7 @@ export class CommandCenter {
|
||||
});
|
||||
}
|
||||
|
||||
return sanitize(rawBranchName || '');
|
||||
return sanitizeBranchName(rawBranchName || '', branchWhitespaceChar);
|
||||
}
|
||||
|
||||
private async _branch(repository: Repository, defaultName?: string, from = false): Promise<void> {
|
||||
|
||||
@@ -401,9 +401,14 @@ export class Git {
|
||||
return new Repository(this, repository, dotGit, logger);
|
||||
}
|
||||
|
||||
async init(repository: string): Promise<void> {
|
||||
await this.exec(repository, ['init']);
|
||||
return;
|
||||
async init(repository: string, options: { defaultBranch?: string } = {}): Promise<void> {
|
||||
const args = ['init'];
|
||||
|
||||
if (options.defaultBranch && options.defaultBranch !== '') {
|
||||
args.push('-b', options.defaultBranch);
|
||||
}
|
||||
|
||||
await this.exec(repository, args);
|
||||
}
|
||||
|
||||
async clone(url: string, options: ICloneOptions, cancellationToken?: CancellationToken): Promise<string> {
|
||||
|
||||
Reference in New Issue
Block a user