@@ -20,7 +20,7 @@ import { ILogService } from '../../log/common/logService';
2020import { IGitExtensionService } from '../common/gitExtensionService' ;
2121import { IGitService , RepoContext } from '../common/gitService' ;
2222import { parseGitRemotes } from '../common/utils' ;
23- import { API , APIState , Change , Commit , CommitOptions , CommitShortStat , DiffChange , LogOptions , Ref , RefQuery , Repository , RepositoryAccessDetails } from './git' ;
23+ import { API , APIState , Branch , Change , Commit , CommitOptions , CommitShortStat , DiffChange , LogOptions , Ref , RefQuery , Repository , RepositoryAccessDetails } from './git' ;
2424
2525export class GitServiceImpl extends Disposable implements IGitService {
2626
@@ -326,6 +326,25 @@ export class GitServiceImpl extends Disposable implements IGitService {
326326 return await repository ?. getRefs ( query , cancellationToken ) ?? [ ] ;
327327 }
328328
329+ async isBranchProtected ( uri : URI , branch ?: string | Branch ) : Promise < boolean | undefined > {
330+ try {
331+ const gitAPI = this . gitExtensionService . getExtensionApi ( ) ;
332+ const repository = gitAPI ?. getRepository ( uri ) ;
333+ if ( ! repository ) {
334+ return undefined ;
335+ }
336+
337+ const branchToCheck = typeof branch === 'string'
338+ ? await repository . getBranch ( branch )
339+ : branch ;
340+ return repository . isBranchProtected ( branchToCheck ) ;
341+ } catch ( error ) {
342+ const branchLabel = typeof branch === 'string' ? branch : branch ?. name ;
343+ this . logService . error ( `[GitServiceImpl][isBranchProtected] Failed to check branch protection for ${ uri . toString ( ) } ${ branchLabel ? ` (${ branchLabel } )` : '' } : ${ error instanceof Error ? error . message : String ( error ) } ` ) ;
344+ return undefined ;
345+ }
346+ }
347+
329348 async generateRandomBranchName ( uri : URI ) : Promise < string | undefined > {
330349 try {
331350 const gitAPI = this . gitExtensionService . getExtensionApi ( ) ;
0 commit comments