Skip to content

Commit

Permalink
fix(storage): defer clone of submodules (#4550)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieMagee authored and rarkins committed Oct 4, 2019
1 parent a358a88 commit 36b9c4a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 17 deletions.
41 changes: 25 additions & 16 deletions lib/platform/git/storage.ts
Expand Up @@ -110,10 +110,7 @@ export class Storage {
const cloneStart = process.hrtime();
try {
// clone only the default branch
await this._git.clone(config.url, '.', [
'--depth=2',
'--recurse-submodules',
]);
await this._git.clone(config.url, '.', ['--depth=2']);
} catch (err) /* istanbul ignore next */ {
logger.debug({ err }, 'git clone error');
throw new Error('platform-failure');
Expand All @@ -123,6 +120,14 @@ export class Storage {
10;
logger.info({ cloneSeconds }, 'git clone completed');
}
const submodules = await this.getSubmodules();
for (const submodule of submodules) {
try {
await this._git.submoduleUpdate(['--init', '--', submodule]);
} catch (err) {
logger.warn(`Unable to initialise git submodule at ${submodule}`);
}
}
try {
const latestCommitDate = (await this._git!.log({ n: 1 })).latest.date;
logger.debug({ latestCommitDate }, 'latest commit');
Expand Down Expand Up @@ -244,18 +249,7 @@ export class Storage {
if (!exists) {
return [];
}
const submodules: string[] = (
(await this._git!.raw([
'config',
'--file',
'.gitmodules',
'--get-regexp',
'path',
])) || ''
)
.trim()
.split(/[\n\s]/)
.filter((_e: string, i: number) => i % 2);
const submodules = await this.getSubmodules();
const files: string = await this._git!.raw([
'ls-tree',
'-r',
Expand All @@ -274,6 +268,21 @@ export class Storage {
);
}

async getSubmodules() {
return (
(await this._git!.raw([
'config',
'--file',
'.gitmodules',
'--get-regexp',
'path',
])) || ''
)
.trim()
.split(/[\n\s]/)
.filter((_e: string, i: number) => i % 2);
}

async branchExists(branchName: string) {
// First check cache
if (this._config.branchExists[branchName] !== undefined) {
Expand Down
26 changes: 25 additions & 1 deletion test/platform/git/storage.spec.ts
Expand Up @@ -85,7 +85,7 @@ describe('platform/git/storage', () => {
expect(await git.getFileList()).toMatchSnapshot();
});
it('should exclude submodules', async () => {
const repo = await Git(base.path).silent(true);
const repo = Git(base.path).silent(true);
await repo.submoduleAdd(base.path, 'submodule');
await repo.commit('Add submodule');
await git.initRepo({
Expand Down Expand Up @@ -346,5 +346,29 @@ describe('platform/git/storage', () => {
expect(await git.branchExists('renovate/test')).toBe(true);
expect(await git.getBranchCommit('renovate/test')).not.toEqual(cid);
});

it('should fail clone ssh submodule', async () => {
const repo = Git(base.path).silent(true);
await fs.writeFile(
base.path + '/.gitmodules',
'[submodule "test"]\npath=test\nurl=ssh://0.0.0.0'
);
await repo.add('.gitmodules');
await repo.raw([
'update-index',
'--add',
'--cacheinfo',
'160000',
'4b825dc642cb6eb9a060e54bf8d69288fbee4904',
'test',
]);
await repo.commit('Add submodule');
await git.initRepo({
localDir: tmpDir.path,
url: base.path,
});
expect(await fs.exists(tmpDir.path + '/.gitmodules')).toBeTruthy();
repo.reset(['--hard', 'HEAD^']);
});
});
});

0 comments on commit 36b9c4a

Please sign in to comment.