@@ -15,7 +15,7 @@ import { BitbucketConnectionConfig, GerritConnectionConfig, GiteaConnectionConfi
1515import { ProjectVisibility } from "azure-devops-node-api/interfaces/CoreInterfaces.js" ;
1616import path from 'path' ;
1717import { glob } from 'glob' ;
18- import { getOriginUrl , isPathAValidGitRepoRoot , isUrlAValidGitRepo } from './git.js' ;
18+ import { getLocalDefaultBranch , getOriginUrl , isPathAValidGitRepoRoot , isUrlAValidGitRepo } from './git.js' ;
1919import assert from 'assert' ;
2020import GitUrlParse from 'git-url-parse' ;
2121import { RepoMetadata } from '@sourcebot/shared' ;
@@ -118,6 +118,7 @@ export const createGitHubRepoRecord = ({
118118 cloneUrl : cloneUrl . toString ( ) ,
119119 webUrl : repo . html_url ,
120120 name : repoName ,
121+ defaultBranch : repo . default_branch ,
121122 displayName : repoDisplayName ,
122123 imageUrl : repo . owner . avatar_url ,
123124 isFork : repo . fork ,
@@ -185,6 +186,7 @@ export const compileGitlabConfig = async (
185186 cloneUrl : cloneUrl . toString ( ) ,
186187 webUrl : projectUrl ,
187188 name : repoName ,
189+ defaultBranch : project . default_branch ,
188190 displayName : repoDisplayName ,
189191 imageUrl : avatarUrl ,
190192 isFork : isFork ,
@@ -257,6 +259,7 @@ export const compileGiteaConfig = async (
257259 webUrl : repo . html_url ,
258260 name : repoName ,
259261 displayName : repoDisplayName ,
262+ defaultBranch : repo . default_branch ,
260263 imageUrl : repo . owner ?. avatar_url ,
261264 isFork : repo . fork ! ,
262265 isPublic : isPublic ,
@@ -339,6 +342,10 @@ export const compileGerritConfig = async (
339342 webUrl : webUrl ,
340343 name : repoName ,
341344 displayName : repoDisplayName ,
345+ // @note : the gerrit api doesn't return the default branch (without a seperate query).
346+ // Instead, the default branch will be set once the repo is cloned.
347+ // @see : repoIndexManager.ts
348+ defaultBranch : undefined ,
342349 isFork : false ,
343350 isArchived : false ,
344351 org : {
@@ -444,6 +451,7 @@ export const compileBitbucketConfig = async (
444451 const repoName = path . join ( repoNameRoot , displayName ) ;
445452 const cloneUrl = getCloneUrl ( repo ) ;
446453 const webUrl = getWebUrl ( repo ) ;
454+ const defaultBranch = isServer ? ( repo as BitbucketServerRepository ) . defaultBranch : ( repo as BitbucketCloudRepository ) . mainbranch ?. name ;
447455
448456 const record : RepoData = {
449457 external_id : externalId ,
@@ -453,6 +461,7 @@ export const compileBitbucketConfig = async (
453461 webUrl : webUrl ,
454462 name : repoName ,
455463 displayName : displayName ,
464+ defaultBranch,
456465 isFork : isFork ,
457466 isPublic : isPublic ,
458467 isArchived : isArchived ,
@@ -557,6 +566,8 @@ export const compileGenericGitHostConfig_file = async (
557566
558567 const remoteUrl = GitUrlParse ( origin ) ;
559568
569+ const defaultBranch = await getLocalDefaultBranch ( { path : repoPath } ) ;
570+
560571 // @note : matches the naming here:
561572 // https://github.com/sourcebot-dev/zoekt/blob/main/gitindex/index.go#L293
562573 // Go's url.URL.Host includes the port if present (even default ports like 443),
@@ -573,6 +584,7 @@ export const compileGenericGitHostConfig_file = async (
573584 cloneUrl : `file://${ repoPath } ` ,
574585 name : repoName ,
575586 displayName : repoName ,
587+ defaultBranch,
576588 isFork : false ,
577589 isArchived : false ,
578590 org : {
@@ -612,7 +624,6 @@ export const compileGenericGitHostConfig_file = async (
612624 }
613625}
614626
615-
616627export const compileGenericGitHostConfig_url = async (
617628 config : GenericGitHostConnectionConfig ,
618629 connectionId : number ,
@@ -645,6 +656,10 @@ export const compileGenericGitHostConfig_url = async (
645656 cloneUrl : remoteUrl . toString ( ) ,
646657 name : repoName ,
647658 displayName : repoName ,
659+ // @note : we can't determine the default branch from the remote url.
660+ // Instead, the default branch will be set once the repo is cloned.
661+ // @see : repoIndexManager.ts
662+ defaultBranch : undefined ,
648663 isFork : false ,
649664 isArchived : false ,
650665 org : {
@@ -719,6 +734,7 @@ export const compileAzureDevOpsConfig = async (
719734 webUrl : webUrl ,
720735 name : repoName ,
721736 displayName : repoDisplayName ,
737+ defaultBranch : repo . defaultBranch ,
722738 imageUrl : null ,
723739 isFork : ! ! repo . isFork ,
724740 isArchived : false ,
0 commit comments