mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-11 22:46:27 +00:00
feat(git): initialise submodules when cloning repos (#4353)
See https://git-scm.com/docs/git-clone#Documentation/git-clone.txt---recurse-submodulesltpathspec Fixes #1356
This commit is contained in:
parent
8554df5c61
commit
e792268cbb
3 changed files with 44 additions and 3 deletions
|
@ -110,7 +110,10 @@ export class Storage {
|
||||||
const cloneStart = process.hrtime();
|
const cloneStart = process.hrtime();
|
||||||
try {
|
try {
|
||||||
// clone only the default branch
|
// clone only the default branch
|
||||||
await this._git.clone(config.url, '.', ['--depth=2']);
|
await this._git.clone(config.url, '.', [
|
||||||
|
'--depth=2',
|
||||||
|
'--recurse-submodules',
|
||||||
|
]);
|
||||||
} catch (err) /* istanbul ignore next */ {
|
} catch (err) /* istanbul ignore next */ {
|
||||||
logger.debug({ err }, 'git clone error');
|
logger.debug({ err }, 'git clone error');
|
||||||
throw new Error('platform-failure');
|
throw new Error('platform-failure');
|
||||||
|
@ -241,7 +244,19 @@ export class Storage {
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
const files = await this._git!.raw([
|
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 files: string = await this._git!.raw([
|
||||||
'ls-tree',
|
'ls-tree',
|
||||||
'-r',
|
'-r',
|
||||||
'--name-only',
|
'--name-only',
|
||||||
|
@ -251,7 +266,12 @@ export class Storage {
|
||||||
if (!files) {
|
if (!files) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
return files.split('\n').filter(Boolean);
|
return files
|
||||||
|
.split('\n')
|
||||||
|
.filter(Boolean)
|
||||||
|
.filter((file: string) =>
|
||||||
|
submodules.every((submodule: string) => !file.startsWith(submodule))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async branchExists(branchName: string) {
|
async branchExists(branchName: string) {
|
||||||
|
|
|
@ -11,6 +11,15 @@ Array [
|
||||||
|
|
||||||
exports[`platform/git/storage getFile(filePath, branchName) returns null for 404 1`] = `[Error: repository-changed]`;
|
exports[`platform/git/storage getFile(filePath, branchName) returns null for 404 1`] = `[Error: repository-changed]`;
|
||||||
|
|
||||||
|
exports[`platform/git/storage getFileList() should exclude submodules 1`] = `
|
||||||
|
Array [
|
||||||
|
".gitmodules",
|
||||||
|
"file_to_delete",
|
||||||
|
"master_file",
|
||||||
|
"past_file",
|
||||||
|
]
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`platform/git/storage getFileList() should return the correct files 1`] = `
|
exports[`platform/git/storage getFileList() should return the correct files 1`] = `
|
||||||
Array [
|
Array [
|
||||||
"file_to_delete",
|
"file_to_delete",
|
||||||
|
|
|
@ -84,6 +84,18 @@ describe('platform/git/storage', () => {
|
||||||
expect(await git.getFileList('renovate/future_branch')).toMatchSnapshot();
|
expect(await git.getFileList('renovate/future_branch')).toMatchSnapshot();
|
||||||
expect(await git.getFileList()).toMatchSnapshot();
|
expect(await git.getFileList()).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
it('should exclude submodules', async () => {
|
||||||
|
const repo = await Git(base.path).silent(true);
|
||||||
|
await repo.submoduleAdd(base.path, 'submodule');
|
||||||
|
await repo.commit('Add submodule');
|
||||||
|
await git.initRepo({
|
||||||
|
localDir: tmpDir.path,
|
||||||
|
url: base.path,
|
||||||
|
});
|
||||||
|
expect(await fs.exists(tmpDir.path + '/.gitmodules')).toBeTruthy();
|
||||||
|
expect(await git.getFileList()).toMatchSnapshot();
|
||||||
|
repo.reset(['--hard', 'HEAD^']);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
describe('branchExists(branchName)', () => {
|
describe('branchExists(branchName)', () => {
|
||||||
it('should return true if found', async () => {
|
it('should return true if found', async () => {
|
||||||
|
|
Loading…
Reference in a new issue