From fd1346ed6b98fe6f4f1a55603d47f5440d4e1025 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Mon, 23 May 2022 16:57:09 +0200 Subject: [PATCH] fix: ignore .git directory in `init` empty check (#208) --- src/cli/init.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cli/init.ts b/src/cli/init.ts index 43aaacf5..e00c8dc5 100644 --- a/src/cli/init.ts +++ b/src/cli/init.ts @@ -20,6 +20,9 @@ OPTIONS: -h, --help Prints help information `; +const CONFIRM_EMPTY_MESSAGE = + "The target directory is not empty (files could get overwritten). Do you want to continue anyway?"; + export interface Args { help: boolean; } @@ -48,12 +51,9 @@ async function init(directory: string) { try { const dir = [...Deno.readDirSync(directory)]; - if ( - dir.length > 0 && - !confirm( - "The target directory is not empty (files could get overwritten). Do you want to continue anyway?", - ) - ) { + const isEmpty = dir.length === 0 || + dir.length === 1 && dir[0].name === ".git"; + if (!isEmpty && !confirm(CONFIRM_EMPTY_MESSAGE)) { error("Directory is not empty."); } } catch (err) {