@@ -729,7 +729,6 @@ export const gitlabConnector: ConnectorConfig = {
729729 }
730730
731731 if ( state . phase === 'repo' ) {
732- const userRef = typeof sourceConfig . ref === 'string' ? sourceConfig . ref . trim ( ) : ''
733732 const ref = await resolveRef ( sourceConfig , syncContext , apiBase , encodedProject , accessToken )
734733 const extSet = parseExtensions ( sourceConfig . fileExtensions )
735734 const rawPrefix =
@@ -759,16 +758,14 @@ export const gitlabConnector: ConnectorConfig = {
759758
760759 if ( ! response . ok ) {
761760 if ( response . status === 404 ) {
762- if ( userRef ) {
763- throw new Error (
764- `GitLab branch "${ userRef } " not found for project ${ sourceConfig . project } . Check the Branch setting.`
765- )
766- }
767- logger . warn ( 'GitLab repository tree empty; skipping files' , {
768- host,
769- project : encodedProject ,
770- ref,
771- } )
761+ logger . warn (
762+ 'GitLab repository tree returned 404; skipping files (empty repo or no tree)' ,
763+ {
764+ host,
765+ project : encodedProject ,
766+ ref,
767+ }
768+ )
772769 const adv = advance ( 'repo' )
773770 return { documents : [ ] , nextCursor : adv . nextCursor , hasMore : adv . hasMore }
774771 }
@@ -1068,6 +1065,24 @@ export const gitlabConnector: ConnectorConfig = {
10681065 }
10691066 }
10701067
1068+ const userRef = typeof sourceConfig . ref === 'string' ? sourceConfig . ref . trim ( ) : ''
1069+ if ( userRef && activePhases ( choice ) . includes ( 'repo' ) ) {
1070+ const branchResponse = await fetchWithRetry (
1071+ `${ apiBase } /projects/${ encodedProject } /repository/branches/${ encodeURIComponent ( userRef ) } ` ,
1072+ { method : 'GET' , headers : authHeaders ( accessToken ) } ,
1073+ VALIDATE_RETRY_OPTIONS
1074+ )
1075+ if ( branchResponse . status === 404 ) {
1076+ return { valid : false , error : `Branch "${ userRef } " not found in project "${ project } "` }
1077+ }
1078+ if ( ! branchResponse . ok ) {
1079+ return {
1080+ valid : false ,
1081+ error : `Cannot verify branch "${ userRef } ": ${ branchResponse . status } ` ,
1082+ }
1083+ }
1084+ }
1085+
10711086 return { valid : true }
10721087 } catch ( error ) {
10731088 return { valid : false , error : getErrorMessage ( error , 'Failed to validate configuration' ) }
0 commit comments