diff --git a/packages/aws-cdk/lib/init.ts b/packages/aws-cdk/lib/init.ts index 1937ddf46e122..f0475873c3691 100644 --- a/packages/aws-cdk/lib/init.ts +++ b/packages/aws-cdk/lib/init.ts @@ -208,7 +208,7 @@ async function initializeProject(template: InitTemplate, language: string, canUs async function assertIsEmptyDirectory() { const files = await fs.readdir(process.cwd()); - if (files.length !== 0) { + if (files.filter(f => !f.startsWith('.')).length !== 0) { throw new Error('`cdk init` cannot be run in a non-empty directory!'); } } diff --git a/packages/aws-cdk/test/test.init.ts b/packages/aws-cdk/test/test.init.ts index 10da8c23535b2..694327ca8dccd 100644 --- a/packages/aws-cdk/test/test.init.ts +++ b/packages/aws-cdk/test/test.init.ts @@ -45,6 +45,18 @@ export = { test.equal(true, await fs.pathExists('package.json')); test.equal(true, await fs.pathExists('bin')); + test.done(); + }, + + async 'git directory does not throw off the initer!'(test: Test) { + fs.mkdirSync('.git'); + + await cliInit('app', 'typescript', false); + + // Check that package.json and bin/ got created in the current directory + test.equal(true, await fs.pathExists('package.json')); + test.equal(true, await fs.pathExists('bin')); + test.done(); } };