Skip to content
Snippets Groups Projects
Unverified Commit 939f3d6a authored by Michael Kriese's avatar Michael Kriese Committed by GitHub
Browse files

feat(git-submodules): fetch default branch (#7391)

parent 78a3f604
No related branches found
No related tags found
No related merge requests found
...@@ -27,6 +27,13 @@ describe('lib/manager/gitsubmodules/extract', () => { ...@@ -27,6 +27,13 @@ describe('lib/manager/gitsubmodules/extract', () => {
} }
return git.raw(options); return git.raw(options);
}, },
listRemote(): Response<string> {
return partial<Response<string>>(
Promise.resolve(
'ref: refs/heads/main HEAD\n5701164b9f5edba1f6ca114c491a564ffb55a964 HEAD'
)
);
},
}; };
}); });
}); });
...@@ -38,6 +45,7 @@ describe('lib/manager/gitsubmodules/extract', () => { ...@@ -38,6 +45,7 @@ describe('lib/manager/gitsubmodules/extract', () => {
).toBeNull(); ).toBeNull();
res = await extractPackageFile('', '.gitmodules.2', { localDir }); res = await extractPackageFile('', '.gitmodules.2', { localDir });
expect(res.deps).toHaveLength(1); expect(res.deps).toHaveLength(1);
expect(res.deps[0].registryUrls[1]).toEqual('main');
res = await extractPackageFile('', '.gitmodules.3', { localDir }); res = await extractPackageFile('', '.gitmodules.3', { localDir });
expect(res.deps).toHaveLength(1); expect(res.deps).toHaveLength(1);
res = await extractPackageFile('', '.gitmodules.4', { localDir }); res = await extractPackageFile('', '.gitmodules.4', { localDir });
......
...@@ -34,9 +34,17 @@ async function getUrl( ...@@ -34,9 +34,17 @@ async function getUrl(
return URL.resolve(`${remoteUrl}/`, path); return URL.resolve(`${remoteUrl}/`, path);
} }
const headRefRe = /ref: refs\/heads\/(?<branch>\w+)\s/;
async function getDefaultBranch(subModuleUrl: string): Promise<string> {
const val = await Git().listRemote(['--symref', subModuleUrl, 'HEAD']);
return headRefRe.exec(val)?.groups?.branch ?? 'master';
}
async function getBranch( async function getBranch(
gitModulesPath: string, gitModulesPath: string,
submoduleName: string submoduleName: string,
subModuleUrl: string
): Promise<string> { ): Promise<string> {
return ( return (
(await Git().raw([ (await Git().raw([
...@@ -45,7 +53,7 @@ async function getBranch( ...@@ -45,7 +53,7 @@ async function getBranch(
gitModulesPath, gitModulesPath,
'--get', '--get',
`submodule.${submoduleName}.branch`, `submodule.${submoduleName}.branch`,
])) || 'master' ])) || (await getDefaultBranch(subModuleUrl))
).trim(); ).trim();
} }
...@@ -99,8 +107,12 @@ export default async function extractPackageFile( ...@@ -99,8 +107,12 @@ export default async function extractPackageFile(
const [currentValue] = (await git.subModule(['status', path])) const [currentValue] = (await git.subModule(['status', path]))
.trim() .trim()
.split(/[+\s]/); .split(/[+\s]/);
const submoduleBranch = await getBranch(gitModulesPath, name);
const subModuleUrl = await getUrl(git, gitModulesPath, name); const subModuleUrl = await getUrl(git, gitModulesPath, name);
const submoduleBranch = await getBranch(
gitModulesPath,
name,
subModuleUrl
);
return { return {
depName: path, depName: path,
registryUrls: [subModuleUrl, submoduleBranch], registryUrls: [subModuleUrl, submoduleBranch],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment