mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 04:49:35 +00:00
💄
This commit is contained in:
parent
406f710b39
commit
6c504e7ee3
|
@ -936,14 +936,14 @@
|
|||
"usesOnlineServices"
|
||||
]
|
||||
},
|
||||
"git.createBranchNameConvention.regexp": {
|
||||
"git.branchValidationRegex": {
|
||||
"type": "string",
|
||||
"description": "%config.createBranchNameConvention.regexp%",
|
||||
"description": "%config.branchValidationRegex%",
|
||||
"default": ""
|
||||
},
|
||||
"git.createBranchWhitespaceChar": {
|
||||
"git.branchWhitespaceChar": {
|
||||
"type": "string",
|
||||
"description": "%config.createBranchWhitespaceChar%",
|
||||
"description": "%config.branchWhitespaceChar%",
|
||||
"default": "-"
|
||||
},
|
||||
"git.confirmSync": {
|
||||
|
|
|
@ -72,8 +72,8 @@
|
|||
"config.checkoutType.local": "Show only local branches.",
|
||||
"config.checkoutType.tags": "Show only tags.",
|
||||
"config.checkoutType.remote": "Show only remote branches.",
|
||||
"config.createBranchNameConvention.regexp": "The regex that is used to match create branch against convention.",
|
||||
"config.createBranchWhitespaceChar": "The char to replace whitespace in branch name when creating branch.",
|
||||
"config.branchValidationRegex": "A regular expression to validate new branch names.",
|
||||
"config.branchWhitespaceChar": "The character to replace whitespace in new branch names.",
|
||||
"config.ignoreLegacyWarning": "Ignores the legacy Git warning.",
|
||||
"config.ignoreMissingGitWarning": "Ignores the warning when Git is missing.",
|
||||
"config.ignoreLimitWarning": "Ignores the warning when there are too many changes in a repository.",
|
||||
|
@ -102,4 +102,4 @@
|
|||
"colors.ignored": "Color for ignored resources.",
|
||||
"colors.conflict": "Color for resources with conflicts.",
|
||||
"colors.submodule": "Color for submodule resources."
|
||||
}
|
||||
}
|
|
@ -1261,32 +1261,42 @@ export class CommandCenter {
|
|||
await choice.run(repository);
|
||||
}
|
||||
|
||||
private removeBranchNameWhitespace(name: string) {
|
||||
const config = workspace.getConfiguration('git');
|
||||
return name.replace(/^\.|\/\.|\.\.|~|\^|:|\/$|\.lock$|\.lock\/|\\|\*|\s|^\s*$|\.|\[|\]|$/g, config.createBranchWhitespaceChar);
|
||||
}
|
||||
|
||||
@command('git.branch', { repository: true })
|
||||
async branch(repository: Repository): Promise<void> {
|
||||
const config = workspace.getConfiguration('git');
|
||||
const validateName = new RegExp(config.createBranchNameConvention.regexp);
|
||||
const branchValidationRegex = config.get<string>('branchValidationRegex')!;
|
||||
const branchWhitespaceChar = config.get<string>('branchWhitespaceChar')!;
|
||||
const validateName = new RegExp(branchValidationRegex);
|
||||
const sanitize = (name: string) => {
|
||||
name = name.trim();
|
||||
|
||||
if (!name) {
|
||||
return name;
|
||||
}
|
||||
|
||||
return name.replace(/^\.|\/\.|\.\.|~|\^|:|\/$|\.lock$|\.lock\/|\\|\*|\s|^\s*$|\.|\[|\]$/g, branchWhitespaceChar);
|
||||
};
|
||||
|
||||
const result = await window.showInputBox({
|
||||
placeHolder: localize('branch name', "Branch name"),
|
||||
prompt: localize('provide branch name', "Please provide a branch name"),
|
||||
ignoreFocusOut: true,
|
||||
validateInput: (name: string) => {
|
||||
if (validateName.test(this.removeBranchNameWhitespace(name))) {
|
||||
if (validateName.test(sanitize(name))) {
|
||||
return null;
|
||||
}
|
||||
return `${localize('branch name format invalid', "Have to be in the format")} : ${config.createBranchNameConvention.regexp}`;
|
||||
|
||||
return localize('branch name format invalid', "Branch name needs to match regex: {0}", branchValidationRegex);
|
||||
}
|
||||
});
|
||||
|
||||
if (!result) {
|
||||
const name = sanitize(result || '');
|
||||
|
||||
if (!name) {
|
||||
return;
|
||||
}
|
||||
|
||||
const name = this.removeBranchNameWhitespace(result);
|
||||
await repository.branch(name, true);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue