Skip to content
Snippets Groups Projects
Commit 65839b78 authored by Rhys Arkins's avatar Rhys Arkins
Browse files

fix(git-submodules): add try-catch around extract phase

parent 989caae2
No related merge requests found
...@@ -3,6 +3,7 @@ import Git from 'simple-git/promise'; ...@@ -3,6 +3,7 @@ import Git from 'simple-git/promise';
import upath from 'upath'; import upath from 'upath';
import * as datasourceGitSubmodules from '../../datasource/git-submodules'; import * as datasourceGitSubmodules from '../../datasource/git-submodules';
import { logger } from '../../logger';
import { ManagerConfig, PackageFile } from '../common'; import { ManagerConfig, PackageFile } from '../common';
type GitModule = { type GitModule = {
...@@ -52,26 +53,28 @@ async function getModules( ...@@ -52,26 +53,28 @@ async function getModules(
git: Git.SimpleGit, git: Git.SimpleGit,
gitModulesPath: string gitModulesPath: string
): Promise<GitModule[]> { ): Promise<GitModule[]> {
const modules = (
(await git.raw([
'config',
'--file',
gitModulesPath,
'--get-regexp',
'path',
])) ?? /* istanbul ignore next: should never happen */ ''
)
.trim()
.split(/\n/)
.filter((s) => !!s);
const res: GitModule[] = []; const res: GitModule[] = [];
try {
const modules = (
(await git.raw([
'config',
'--file',
gitModulesPath,
'--get-regexp',
'path',
])) ?? /* istanbul ignore next: should never happen */ ''
)
.trim()
.split(/\n/)
.filter((s) => !!s);
for (const line of modules) { for (const line of modules) {
const [, name, path] = line.split(/submodule\.(.+?)\.path\s(.+)/); const [, name, path] = line.split(/submodule\.(.+?)\.path\s(.+)/);
res.push({ name, path }); res.push({ name, path });
}
} catch (err) /* istanbul ignore next */ {
logger.warn({ err }, 'Error getting git submodules during extract');
} }
return res; return res;
} }
...@@ -89,21 +92,31 @@ export default async function extractPackageFile( ...@@ -89,21 +92,31 @@ export default async function extractPackageFile(
return null; return null;
} }
const deps = await Promise.all( const deps = (
depNames.map(async ({ name, path }) => { await Promise.all(
const [currentValue] = (await git.subModule(['status', path])) depNames.map(async ({ name, path }) => {
.trim() try {
.split(/[+\s]/); const [currentValue] = (await git.subModule(['status', path]))
const submoduleBranch = await getBranch(gitModulesPath, name); .trim()
const subModuleUrl = await getUrl(git, gitModulesPath, name); .split(/[+\s]/);
return { const submoduleBranch = await getBranch(gitModulesPath, name);
depName: path, const subModuleUrl = await getUrl(git, gitModulesPath, name);
registryUrls: [subModuleUrl, submoduleBranch], return {
currentValue, depName: path,
currentDigest: currentValue, registryUrls: [subModuleUrl, submoduleBranch],
}; currentValue,
}) currentDigest: currentValue,
); };
} catch (err) /* istanbul ignore next */ {
logger.warn(
{ err },
'Error mapping git submodules during extraction'
);
return null;
}
})
)
).filter(Boolean);
return { deps, datasource: datasourceGitSubmodules.id }; return { deps, datasource: datasourceGitSubmodules.id };
} }
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