Skip to content

Commit

Permalink
fix(C3): make sure to always warn developers trying to use git when t…
Browse files Browse the repository at this point in the history
…heir git instance is not properly configured (#6373)
  • Loading branch information
dario-piotrowicz authored Jul 30, 2024
1 parent 6a51aa3 commit 0ffe17d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/slimy-mangos-punch.md
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion packages/create-cloudflare/src/__tests__/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 15 additions & 17 deletions packages/create-cloudflare/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) => {
Expand Down

0 comments on commit 0ffe17d

Please sign in to comment.