Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a check for existing .git directory (and skip if one is found). #5953

Merged
merged 4 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
natemoo-re marked this conversation as resolved.
Show resolved Hide resolved
---

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