From 5c64324c0a1b06e836c3d53668940faca4cb517d Mon Sep 17 00:00:00 2001 From: Chris Banford Date: Thu, 26 Jan 2023 21:34:49 +0100 Subject: [PATCH] Add a check for existing .git directory (and skip if one is found). (#5953) * Add a check for existing .git directory (and skip if one is found). * Changeset attempt :-) * Update .changeset/try-button-rumor.md Co-authored-by: Nate Moore --- .changeset/try-button-rumor.md | 5 +++++ packages/create-astro/src/index.ts | 12 ++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 .changeset/try-button-rumor.md diff --git a/.changeset/try-button-rumor.md b/.changeset/try-button-rumor.md new file mode 100644 index 000000000000..4196822ba029 --- /dev/null +++ b/.changeset/try-button-rumor.md @@ -0,0 +1,5 @@ +--- +"create-astro": patch +--- + +Check for a pre-existing .git directory and if found, skip trying to create a new one. diff --git a/packages/create-astro/src/index.ts b/packages/create-astro/src/index.ts index f1571398f6a5..71c8a2ad58fb 100644 --- a/packages/create-astro/src/index.ts +++ b/packages/create-astro/src/index.ts @@ -298,8 +298,16 @@ export async function main() { if (args.dryRun) { ora().info(dim(`--dry-run enabled, skipping.`)); } else if (gitResponse) { - await execaCommand('git init', { cwd }); - ora().succeed('Git repository created!'); + // Add a check to see if there is already a .git directory and skip 'git init' if yes (with msg to output) + const gitDir = './.git'; + if (fs.existsSync(gitDir)) { + ora().info( + dim('A .git directory already exists. Skipping creating a new Git repository.') + ); + } else { + await execaCommand('git init', { cwd }); + ora().succeed('Git repository created!'); + } } else { await info( 'Sounds good!',