diff --git a/lib/modules/manager/git-submodules/__fixtures__/.gitmodules.7 b/lib/modules/manager/git-submodules/__fixtures__/.gitmodules.7 new file mode 100644 index 00000000000000..cbdf78aec13036 --- /dev/null +++ b/lib/modules/manager/git-submodules/__fixtures__/.gitmodules.7 @@ -0,0 +1,4 @@ +[submodule "PowerShell-Docs"] + path = PowerShell-Docs + url = git@github.com:PowerShell/PowerShell-Docs + branch = . diff --git a/lib/modules/manager/git-submodules/extract.spec.ts b/lib/modules/manager/git-submodules/extract.spec.ts index def69fc669af10..45c117e24b19d0 100644 --- a/lib/modules/manager/git-submodules/extract.spec.ts +++ b/lib/modules/manager/git-submodules/extract.spec.ts @@ -299,5 +299,42 @@ describe('modules/manager/git-submodules/extract', () => { ], }); }); + + it('fallback to current branch if special value is detected', async () => { + gitMock.branch.mockResolvedValueOnce({ + all: ['staging', 'main'], + branches: { + staging: { + current: true, + name: 'staging', + commit: '9eeb873', + label: 'staging branch', + linkedWorkTree: false, + }, + main: { + current: false, + name: 'main', + commit: 'e14c7e1', + label: 'main branch', + linkedWorkTree: false, + }, + }, + current: 'staging', + detached: false, + }); + + const res = await extractPackageFile('', '.gitmodules.7', {}); + expect(res).toEqual({ + datasource: 'git-refs', + deps: [ + { + currentDigest: '4b825dc642cb6eb9a060e54bf8d69288fbee4904', + currentValue: 'staging', + depName: 'PowerShell-Docs', + packageName: 'https://github.com/PowerShell/PowerShell-Docs', + }, + ], + }); + }); }); }); diff --git a/lib/modules/manager/git-submodules/extract.ts b/lib/modules/manager/git-submodules/extract.ts index 7623ba024a5075..b870183b9ac173 100644 --- a/lib/modules/manager/git-submodules/extract.ts +++ b/lib/modules/manager/git-submodules/extract.ts @@ -54,19 +54,24 @@ async function getDefaultBranch(subModuleUrl: string): Promise { } async function getBranch( + git: SimpleGit, gitModulesPath: string, submoduleName: string, subModuleUrl: string ): Promise { - return ( - (await Git(simpleGitConfig()).raw([ + const branchFromConfig = ( + await Git(simpleGitConfig()).raw([ 'config', '--file', gitModulesPath, '--get', `submodule.${submoduleName}.branch`, - ])) || (await getDefaultBranch(subModuleUrl)) + ]) ).trim(); + + return branchFromConfig === '.' + ? (await git.branch(['--show-current'])).current.trim() + : branchFromConfig || (await getDefaultBranch(subModuleUrl)).trim(); } async function getModules( @@ -123,6 +128,7 @@ export default async function extractPackageFile( const subModuleUrl = await getUrl(git, gitModulesPath, name); const httpSubModuleUrl = getHttpUrl(subModuleUrl); const currentValue = await getBranch( + git, gitModulesPath, name, httpSubModuleUrl