diff options
-rw-r--r-- | .changeset/try-button-rumor.md | 5 | ||||
-rw-r--r-- | packages/create-astro/src/index.ts | 12 |
2 files changed, 15 insertions, 2 deletions
diff --git a/.changeset/try-button-rumor.md b/.changeset/try-button-rumor.md new file mode 100644 index 000000000..4196822ba --- /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 f1571398f..71c8a2ad5 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!', |