diff options
author | 2023-01-26 21:34:49 +0100 | |
---|---|---|
committer | 2023-01-26 15:34:49 -0500 | |
commit | 5c64324c0a1b06e836c3d53668940faca4cb517d (patch) | |
tree | 486445058b2413f3ccff9bd866ec772c85801bfb | |
parent | a88363ce798e8cd83db2ada47253017dd7f7678e (diff) | |
download | astro-5c64324c0a1b06e836c3d53668940faca4cb517d.tar.gz astro-5c64324c0a1b06e836c3d53668940faca4cb517d.tar.zst astro-5c64324c0a1b06e836c3d53668940faca4cb517d.zip |
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 <natemoo-re@users.noreply.github.com>
-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!', |