Skip to content

Commit

Permalink
C3: Detect production branch when creating pages project (#3644)
Browse files Browse the repository at this point in the history
* C3: Detect production branch when creating pages project

* changeset

* Addressing PR feedback
  • Loading branch information
jculvey authored Jul 20, 2023
1 parent b58663a commit 775eb3b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-apes-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-cloudflare": patch
---

Detect production branch when creating pages project
19 changes: 19 additions & 0 deletions packages/create-cloudflare/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,22 @@ export async function initializeGit(cwd: string) {
await runCommand(`git init`, { useSpinner: false, silent: true, cwd });
}
}

export async function getProductionBranch(cwd: string) {
try {
const productionBranch = await runCommand(
// "git branch --show-current", // git@^2.22
"git rev-parse --abbrev-ref HEAD", // git@^1.6.3
{
silent: true,
cwd,
useSpinner: false,
captureOutput: true,
}
);

return productionBranch.trim();
} catch (err) {}

return "main";
}
2 changes: 1 addition & 1 deletion packages/create-cloudflare/src/helpers/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const runCommand = async (

return printAsyncStatus({
useSpinner: opts.useSpinner ?? opts.silent,
startText: opts.startText || command.join(" "),
startText: opts.startText || command.join(" ").trim(),
doneText: opts.doneText,
promise() {
const [executable, ...args] = command;
Expand Down
6 changes: 4 additions & 2 deletions packages/create-cloudflare/src/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { processArgument, spinner } from "helpers/interactive";
import { detectPackageManager } from "helpers/packages";
import { C3_DEFAULTS } from "./cli";
import {
getProductionBranch,
gitCommit,
offerGit,
offerToDeploy,
Expand Down Expand Up @@ -135,7 +136,8 @@ const createProject = async (ctx: PagesGeneratorContext) => {
? `--compatibility-flags ${compatFlags}`
: "";

const cmd = `${npx} wrangler pages project create ${ctx.project.name} --production-branch main ${compatFlagsArg}`;
const productionBranch = await getProductionBranch(ctx.project.path);
const cmd = `${npx} wrangler pages project create ${ctx.project.name} --production-branch ${productionBranch} ${compatFlagsArg}`;

try {
await retry(CREATE_PROJECT_RETRIES, async () =>
Expand All @@ -144,7 +146,7 @@ const createProject = async (ctx: PagesGeneratorContext) => {
cwd: ctx.project.path,
env: { CLOUDFLARE_ACCOUNT_ID },
startText: "Creating Pages project",
doneText: `${brandColor("created")} ${dim(`via \`${cmd}\``)}`,
doneText: `${brandColor("created")} ${dim(`via \`${cmd.trim()}\``)}`,
})
);
} catch (error) {
Expand Down

0 comments on commit 775eb3b

Please sign in to comment.