Git - better validation for the branchProtection setting (#179183)

This commit is contained in:
Ladislau Szomoru 2023-04-04 23:10:17 +02:00 committed by GitHub
parent cde5bfd7a1
commit 20aee57124
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2360,7 +2360,12 @@ export class Repository implements Disposable {
private updateBranchProtectionMatcher(): void {
const scopedConfig = workspace.getConfiguration('git', Uri.file(this.repository.root));
const branchProtectionGlobs = scopedConfig.get<string[]>('branchProtection')!.map(bp => bp.trim()).filter(bp => bp !== '');
const branchProtectionConfig = scopedConfig.get<unknown>('branchProtection') ?? [];
const branchProtectionValues = Array.isArray(branchProtectionConfig) ? branchProtectionConfig : [branchProtectionConfig];
const branchProtectionGlobs = branchProtectionValues
.map(bp => typeof bp === 'string' ? bp.trim() : '')
.filter(bp => bp !== '');
if (branchProtectionGlobs.length === 0) {
this.isBranchProtectedMatcher = undefined;