Skip to content

Commit

Permalink
feat(manager/git-submodules): Support for special branch value . (#…
Browse files Browse the repository at this point in the history
…25507)

Co-authored-by: Rhys Arkins <rhys@arkins.net>
  • Loading branch information
AirOne70 and rarkins committed Nov 4, 2023
1 parent b35c55c commit b89c370
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
4 changes: 4 additions & 0 deletions 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 = .
37 changes: 37 additions & 0 deletions lib/modules/manager/git-submodules/extract.spec.ts
Expand Up @@ -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',
},
],
});
});
});
});
12 changes: 9 additions & 3 deletions lib/modules/manager/git-submodules/extract.ts
Expand Up @@ -54,19 +54,24 @@ async function getDefaultBranch(subModuleUrl: string): Promise<string> {
}

async function getBranch(
git: SimpleGit,
gitModulesPath: string,
submoduleName: string,
subModuleUrl: string
): Promise<string> {
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(
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b89c370

Please sign in to comment.