Skip to content

Commit 0ffe17d

Browse files
fix(C3): make sure to always warn developers trying to use git when their git instance is not properly configured (#6373)
1 parent 6a51aa3 commit 0ffe17d

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

.changeset/slimy-mangos-punch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-cloudflare": patch
3+
---
4+
5+
fix: make sure to always warn developers trying to use git when their git instance is not properly configured

packages/create-cloudflare/src/__tests__/git.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ describe("git helpers", () => {
149149
test("happy path", async () => {
150150
const ctx = createTestContext();
151151
mockGitInstalled(true);
152-
mockGitConfig();
153152
mockInsideGitRepo(false);
153+
mockGitConfig();
154154
mockDefaultBranchName();
155155

156156
// Mock user selecting true

packages/create-cloudflare/src/git.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,6 @@ export const offerGit = async (ctx: C3Context) => {
2626
return; // bail early
2727
}
2828

29-
const gitConfigured = await isGitConfigured();
30-
if (!gitConfigured) {
31-
// haven't prompted yet, if provided as --git arg
32-
if (ctx.args.git) {
33-
updateStatus(
34-
"Must configure `user.name` and user.email` to use git. Continuing without git.",
35-
);
36-
}
37-
38-
// override true (--git flag) and undefined (not prompted yet) to false (don't use git)
39-
ctx.args.git = false;
40-
41-
return; // bail early
42-
}
43-
4429
const insideGitRepo = await isInsideGitRepo(ctx.project.path);
4530

4631
if (insideGitRepo) {
@@ -55,9 +40,22 @@ export const offerGit = async (ctx: C3Context) => {
5540
defaultValue: C3_DEFAULTS.git,
5641
});
5742

58-
if (ctx.args.git) {
59-
await initializeGit(ctx.project.path);
43+
if (!ctx.args.git) {
44+
return;
45+
}
46+
47+
const gitConfigured = await isGitConfigured();
48+
if (!gitConfigured) {
49+
updateStatus(
50+
"Must configure `user.name` and user.email` to use git. Continuing without git.",
51+
);
52+
53+
// override ctx.args.git to false (don't use git)
54+
ctx.args.git = false;
55+
return;
6056
}
57+
58+
await initializeGit(ctx.project.path);
6159
};
6260

6361
export const gitCommit = async (ctx: C3Context) => {

0 commit comments

Comments
 (0)