Skip to content

Commit

Permalink
C3: Don't offer git if username and email unconfigured
Browse files Browse the repository at this point in the history
  • Loading branch information
james culveyhouse committed Oct 5, 2023
1 parent 12a6f5e commit 888f0b3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/green-days-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-cloudflare": patch
---

Don't prompt the user to use git if `user.name` and `user.email` haven't been configured
36 changes: 35 additions & 1 deletion packages/create-cloudflare/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ export const printSummary = async (ctx: PagesGeneratorContext) => {

export const offerGit = async (ctx: PagesGeneratorContext) => {
const gitInstalled = await isGitInstalled();

if (!gitInstalled) {
// haven't prompted yet, if provided as --git arg
if (ctx.args.git) {
Expand All @@ -257,6 +256,21 @@ export const offerGit = async (ctx: PagesGeneratorContext) => {
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) return;
Expand Down Expand Up @@ -361,6 +375,26 @@ async function isGitInstalled() {
return (await getGitVersion()) !== null;
}

async function isGitConfigured() {
try {
const userName = await runCommand("git config user.name", {
useSpinner: false,
silent: true,
});
if (!userName) return false;

const email = await runCommand("git config user.name", {
useSpinner: false,
silent: true,
});
if (!email) return false;

return true;
} catch {
return null;
}
}

/**
* Check whether the given current working directory is within a git repository
* by looking for a `.git` directory in this or an ancestor directory.
Expand Down

0 comments on commit 888f0b3

Please sign in to comment.