fix: ignore .git directory in init empty check (#208)

This commit is contained in:
Luca Casonato
2022-05-23 16:57:09 +02:00
committed by GitHub
parent dd59a05eca
commit fd1346ed6b
+6 -6
View File
@@ -20,6 +20,9 @@ OPTIONS:
-h, --help Prints help information -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 { export interface Args {
help: boolean; help: boolean;
} }
@@ -48,12 +51,9 @@ async function init(directory: string) {
try { try {
const dir = [...Deno.readDirSync(directory)]; const dir = [...Deno.readDirSync(directory)];
if ( const isEmpty = dir.length === 0 ||
dir.length > 0 && dir.length === 1 && dir[0].name === ".git";
!confirm( if (!isEmpty && !confirm(CONFIRM_EMPTY_MESSAGE)) {
"The target directory is not empty (files could get overwritten). Do you want to continue anyway?",
)
) {
error("Directory is not empty."); error("Directory is not empty.");
} }
} catch (err) { } catch (err) {