Skip to content

Commit 9b0d743

Browse files
authored
Git - remove git.experimental.inputValidation setting (microsoft#205550)
* Git - remove git.experimental.inputValidation setting * Fix compilation error * Fix migration code
1 parent 248c585 commit 9b0d743

File tree

4 files changed

+33
-72
lines changed

4 files changed

+33
-72
lines changed

extensions/git/package.json

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2759,13 +2759,8 @@
27592759
"default": false
27602760
},
27612761
"git.inputValidation": {
2762-
"type": "string",
2763-
"enum": [
2764-
"always",
2765-
"warn",
2766-
"off"
2767-
],
2768-
"default": "off",
2762+
"type": "boolean",
2763+
"default": false,
27692764
"description": "%config.inputValidation%"
27702765
},
27712766
"git.inputValidationLength": {
@@ -2781,11 +2776,6 @@
27812776
"default": 50,
27822777
"markdownDescription": "%config.inputValidationSubjectLength%"
27832778
},
2784-
"git.experimental.inputValidation": {
2785-
"type": "boolean",
2786-
"default": false,
2787-
"description": "%config.inputValidation%"
2788-
},
27892779
"git.detectSubmodules": {
27902780
"type": "boolean",
27912781
"scope": "resource",

extensions/git/package.nls.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@
198198
"config.openAfterClone.prompt": "Always prompt for action.",
199199
"config.showInlineOpenFileAction": "Controls whether to show an inline Open File action in the Git changes view.",
200200
"config.showPushSuccessNotification": "Controls whether to show a notification when a push is successful.",
201-
"config.inputValidation": "Controls when to show commit message input validation.",
201+
"config.inputValidation": "Controls whether to show commit message input validation diagnostics.",
202202
"config.inputValidationLength": "Controls the commit message length threshold for showing a warning.",
203203
"config.inputValidationSubjectLength": "Controls the commit message subject length threshold for showing a warning. Unset it to inherit the value of `#git.inputValidationLength#`.",
204204
"config.detectSubmodules": "Controls whether to automatically detect Git submodules.",

extensions/git/src/diagnostics.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,38 @@ export class GitCommitInputBoxDiagnosticsManager {
2121
constructor(private readonly model: Model) {
2222
this.diagnostics = languages.createDiagnosticCollection();
2323

24-
mapEvent(filterEvent(workspace.onDidChangeTextDocument, e => e.document.uri.scheme === 'vscode-scm'), e => e.document)(this.onDidChangeTextDocument, this, this.disposables);
25-
filterEvent(workspace.onDidChangeConfiguration, e => e.affectsConfiguration('git.experimental.inputValidation'))(this.onDidChangeConfiguration, this, this.disposables);
24+
this.migrateInputValidationSettings()
25+
.then(() => {
26+
mapEvent(filterEvent(workspace.onDidChangeTextDocument, e => e.document.uri.scheme === 'vscode-scm'), e => e.document)(this.onDidChangeTextDocument, this, this.disposables);
27+
filterEvent(workspace.onDidChangeConfiguration, e => e.affectsConfiguration('git.inputValidation'))(this.onDidChangeConfiguration, this, this.disposables);
28+
});
2629
}
2730

2831
public getDiagnostics(uri: Uri): ReadonlyArray<Diagnostic> {
2932
return this.diagnostics.get(uri) ?? [];
3033
}
3134

35+
private async migrateInputValidationSettings(): Promise<void> {
36+
try {
37+
const config = workspace.getConfiguration('git');
38+
const inputValidation = config.inspect<'always' | 'warn' | 'off' | boolean>('inputValidation');
39+
40+
if (inputValidation === undefined) {
41+
return;
42+
}
43+
44+
// Workspace setting
45+
if (typeof inputValidation.workspaceValue === 'string') {
46+
await config.update('inputValidation', inputValidation.workspaceValue !== 'off', false);
47+
}
48+
49+
// User setting
50+
if (typeof inputValidation.globalValue === 'string') {
51+
await config.update('inputValidation', inputValidation.workspaceValue !== 'off', true);
52+
}
53+
} catch { }
54+
}
55+
3256
private onDidChangeConfiguration(): void {
3357
for (const repository of this.model.repositories) {
3458
this.onDidChangeTextDocument(repository.inputBox.document);
@@ -37,7 +61,7 @@ export class GitCommitInputBoxDiagnosticsManager {
3761

3862
private onDidChangeTextDocument(document: TextDocument): void {
3963
const config = workspace.getConfiguration('git');
40-
const inputValidation = config.get<boolean>('experimental.inputValidation', false) === true;
64+
const inputValidation = config.get<boolean>('inputValidation', false);
4165
if (!inputValidation) {
4266
this.diagnostics.set(document.uri, undefined);
4367
return;

extensions/git/src/repository.ts

Lines changed: 3 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -975,10 +975,9 @@ export class Repository implements Disposable {
975975
this.setCountBadge();
976976
}
977977

978-
validateInput(text: string, position: number): SourceControlInputBoxValidation | undefined {
979-
let tooManyChangesWarning: SourceControlInputBoxValidation | undefined;
978+
validateInput(text: string, _: number): SourceControlInputBoxValidation | undefined {
980979
if (this.isRepositoryHuge) {
981-
tooManyChangesWarning = {
980+
return {
982981
message: l10n.t('Too many changes were detected. Only the first {0} changes will be shown below.', this.isRepositoryHuge.limit),
983982
type: SourceControlInputBoxValidationType.Warning
984983
};
@@ -993,59 +992,7 @@ export class Repository implements Disposable {
993992
}
994993
}
995994

996-
const config = workspace.getConfiguration('git');
997-
const setting = config.get<'always' | 'warn' | 'off'>('inputValidation');
998-
999-
if (setting === 'off') {
1000-
return tooManyChangesWarning;
1001-
}
1002-
1003-
if (/^\s+$/.test(text)) {
1004-
return {
1005-
message: l10n.t('Current commit message only contains whitespace characters'),
1006-
type: SourceControlInputBoxValidationType.Warning
1007-
};
1008-
}
1009-
1010-
let lineNumber = 0;
1011-
let start = 0;
1012-
let match: RegExpExecArray | null;
1013-
const regex = /\r?\n/g;
1014-
1015-
while ((match = regex.exec(text)) && position > match.index) {
1016-
start = match.index + match[0].length;
1017-
lineNumber++;
1018-
}
1019-
1020-
const end = match ? match.index : text.length;
1021-
1022-
const line = text.substring(start, end);
1023-
1024-
let threshold = config.get<number>('inputValidationLength', 50);
1025-
1026-
if (lineNumber === 0) {
1027-
const inputValidationSubjectLength = config.get<number | null>('inputValidationSubjectLength', null);
1028-
1029-
if (inputValidationSubjectLength !== null) {
1030-
threshold = inputValidationSubjectLength;
1031-
}
1032-
}
1033-
1034-
if (line.length <= threshold) {
1035-
if (setting !== 'always') {
1036-
return tooManyChangesWarning;
1037-
}
1038-
1039-
return {
1040-
message: l10n.t('{0} characters left in current line', threshold - line.length),
1041-
type: SourceControlInputBoxValidationType.Information
1042-
};
1043-
} else {
1044-
return {
1045-
message: l10n.t('{0} characters over {1} in current line', line.length - threshold, threshold),
1046-
type: SourceControlInputBoxValidationType.Warning
1047-
};
1048-
}
995+
return undefined;
1049996
}
1050997

1051998
/**

0 commit comments

Comments
 (0)