Skip to content

Commit

Permalink
fix(git-submodules): allow module and path be different (#5437)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice committed Feb 11, 2020
1 parent c2f28bd commit 62e9516
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 17 deletions.
9 changes: 9 additions & 0 deletions lib/manager/git-submodules/__fixtures__/.gitmodules.5
@@ -0,0 +1,9 @@
[submodule "renovate"]
path = deps/renovate
url = https://github.com/renovatebot/renovate.git
[submodule "renovate-pro"]
path = deps/renovate-pro
url = https://github.com/renovatebot/pro.git
[submodule "renovate-config"]
path = deps/renovate-config
url = https://github.com/renovatebot/renovate-config.git
32 changes: 32 additions & 0 deletions lib/manager/git-submodules/__snapshots__/extract.spec.ts.snap
Expand Up @@ -28,6 +28,38 @@ Array [
]
`;

exports[`lib/manager/gitsubmodules/extract extractPackageFile() extract name path mismatch 1`] = `
Array [
Object {
"currentDigest": "4b825dc642cb6eb9a060e54bf8d69288fbee4904",
"currentValue": "4b825dc642cb6eb9a060e54bf8d69288fbee4904",
"depName": "deps/renovate",
"registryUrls": Array [
"https://github.com/renovatebot/renovate.git",
"master",
],
},
Object {
"currentDigest": "4b825dc642cb6eb9a060e54bf8d69288fbee4904",
"currentValue": "4b825dc642cb6eb9a060e54bf8d69288fbee4904",
"depName": "deps/renovate-pro",
"registryUrls": Array [
"https://github.com/renovatebot/pro.git",
"master",
],
},
Object {
"currentDigest": "4b825dc642cb6eb9a060e54bf8d69288fbee4904",
"currentValue": "4b825dc642cb6eb9a060e54bf8d69288fbee4904",
"depName": "deps/renovate-config",
"registryUrls": Array [
"https://github.com/renovatebot/renovate-config.git",
"master",
],
},
]
`;

exports[`lib/manager/gitsubmodules/extract extractPackageFile() extract relative URL 1`] = `
Array [
Object {
Expand Down
6 changes: 6 additions & 0 deletions lib/manager/git-submodules/extract.spec.ts
Expand Up @@ -42,5 +42,11 @@ describe('lib/manager/gitsubmodules/extract', () => {
expect(res.deps).toMatchSnapshot();
expect(res.deps).toHaveLength(1);
});

it('extract name path mismatch', async () => {
const res = await extractPackageFile('', '.gitmodules.5', { localDir });
expect(res.deps).toMatchSnapshot();
expect(res.deps).toHaveLength(3);
});
});
});
55 changes: 38 additions & 17 deletions lib/manager/git-submodules/extract.ts
Expand Up @@ -5,6 +5,11 @@ import URL from 'url';
import { ManagerConfig, PackageFile } from '../common';
import { DATASOURCE_GIT_SUBMODULES } from '../../constants/data-binary-source';

type GitModule = {
name: string;
path: string;
};

async function getUrl(
git: Git.SimpleGit,
gitModulesPath: string,
Expand Down Expand Up @@ -43,15 +48,11 @@ async function getBranch(
).trim();
}

export default async function extractPackageFile(
content: string,
fileName: string,
config: ManagerConfig
): Promise<PackageFile | null> {
const git = Git(config.localDir);
const gitModulesPath = upath.join(config.localDir, fileName);

const depNames = (
async function getModules(
git: Git.SimpleGit,
gitModulesPath: string
): Promise<GitModule[]> {
const modules = (
(await git.raw([
'config',
'--file',
Expand All @@ -61,22 +62,42 @@ export default async function extractPackageFile(
])) || ''
)
.trim()
.split(/[\n\s]/)
.filter((_e: string, i: number) => i % 2);
.split(/\n/)
.filter(s => !!s);

const res: GitModule[] = [];

for (const line of modules) {
const [, name, path] = line.split(/submodule\.(.+?)\.path\s(.+)/);
res.push({ name, path });
}

return res;
}

export default async function extractPackageFile(
content: string,
fileName: string,
config: ManagerConfig
): Promise<PackageFile | null> {
const git = Git(config.localDir);
const gitModulesPath = upath.join(config.localDir, fileName);

const depNames = await getModules(git, gitModulesPath);

if (!depNames.length) {
return null;
}

const deps = await Promise.all(
depNames.map(async depName => {
const currentValue = (await git.subModule(['status', depName]))
depNames.map(async ({ name, path }) => {
const [currentValue] = (await git.subModule(['status', path]))
.trim()
.split(/[+\s]/)[0];
const submoduleBranch = await getBranch(gitModulesPath, depName);
const subModuleUrl = await getUrl(git, gitModulesPath, depName);
.split(/[+\s]/);
const submoduleBranch = await getBranch(gitModulesPath, name);
const subModuleUrl = await getUrl(git, gitModulesPath, name);
return {
depName,
depName: path,
registryUrls: [subModuleUrl, submoduleBranch],
currentValue,
currentDigest: currentValue,
Expand Down

0 comments on commit 62e9516

Please sign in to comment.