Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(manager/git-submodules): Support for special branch value . #25507

Merged
merged 10 commits into from
Nov 4, 2023
4 changes: 4 additions & 0 deletions lib/modules/manager/git-submodules/__fixtures__/.gitmodules.7
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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