Skip to content

Commit

Permalink
Add a check for existing .git directory (and skip if one is found). (#…
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
ZermattChris and natemoo-re committed Jan 26, 2023
1 parent a88363c commit 5c64324
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/try-button-rumor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-astro": patch
---

Check for a pre-existing .git directory and if found, skip trying to create a new one.
12 changes: 10 additions & 2 deletions packages/create-astro/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!',
Expand Down

0 comments on commit 5c64324

Please sign in to comment.