From 0ffe17d0f734cb2e43528f3d2ac491670d6173fe Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Tue, 30 Jul 2024 21:27:34 +0100 Subject: [PATCH] fix(C3): make sure to always warn developers trying to use git when their git instance is not properly configured (#6373) --- .changeset/slimy-mangos-punch.md | 5 +++ .../src/__tests__/git.test.ts | 2 +- packages/create-cloudflare/src/git.ts | 32 +++++++++---------- 3 files changed, 21 insertions(+), 18 deletions(-) create mode 100644 .changeset/slimy-mangos-punch.md diff --git a/.changeset/slimy-mangos-punch.md b/.changeset/slimy-mangos-punch.md new file mode 100644 index 000000000000..648616f2fd59 --- /dev/null +++ b/.changeset/slimy-mangos-punch.md @@ -0,0 +1,5 @@ +--- +"create-cloudflare": patch +--- + +fix: make sure to always warn developers trying to use git when their git instance is not properly configured diff --git a/packages/create-cloudflare/src/__tests__/git.test.ts b/packages/create-cloudflare/src/__tests__/git.test.ts index fbc592409228..e7c07bd656ac 100644 --- a/packages/create-cloudflare/src/__tests__/git.test.ts +++ b/packages/create-cloudflare/src/__tests__/git.test.ts @@ -149,8 +149,8 @@ describe("git helpers", () => { test("happy path", async () => { const ctx = createTestContext(); mockGitInstalled(true); - mockGitConfig(); mockInsideGitRepo(false); + mockGitConfig(); mockDefaultBranchName(); // Mock user selecting true diff --git a/packages/create-cloudflare/src/git.ts b/packages/create-cloudflare/src/git.ts index 64f9232ab5d6..d7d801be64ad 100644 --- a/packages/create-cloudflare/src/git.ts +++ b/packages/create-cloudflare/src/git.ts @@ -26,21 +26,6 @@ export const offerGit = async (ctx: C3Context) => { return; // bail early } - const gitConfigured = await isGitConfigured(); - if (!gitConfigured) { - // haven't prompted yet, if provided as --git arg - if (ctx.args.git) { - updateStatus( - "Must configure `user.name` and user.email` to use git. Continuing without git.", - ); - } - - // override true (--git flag) and undefined (not prompted yet) to false (don't use git) - ctx.args.git = false; - - return; // bail early - } - const insideGitRepo = await isInsideGitRepo(ctx.project.path); if (insideGitRepo) { @@ -55,9 +40,22 @@ export const offerGit = async (ctx: C3Context) => { defaultValue: C3_DEFAULTS.git, }); - if (ctx.args.git) { - await initializeGit(ctx.project.path); + if (!ctx.args.git) { + return; + } + + const gitConfigured = await isGitConfigured(); + if (!gitConfigured) { + updateStatus( + "Must configure `user.name` and user.email` to use git. Continuing without git.", + ); + + // override ctx.args.git to false (don't use git) + ctx.args.git = false; + return; } + + await initializeGit(ctx.project.path); }; export const gitCommit = async (ctx: C3Context) => {