Skip to content

Commit 2d42882

Browse files
fix: ensure wrangler init works with older versions of git (#1209)
Rather than using the recently added `--initial-branch` option, we now just renamed the initial branch using `git branch -m main`. Fixes #1168
1 parent 4e19e9b commit 2d42882

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

.changeset/tender-chefs-provide.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
fix: ensure wrangler init works with older versions of git
6+
7+
Rather than using the recently added `--initial-branch` option, we now just renamed the initial branch using `git branch -m main`.
8+
9+
Fixes https://github.com/cloudflare/wrangler2/issues/1168

packages/wrangler/src/__tests__/init.test.ts

+3
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,9 @@ describe("init", () => {
435435
`);
436436
expect(fs.lstatSync(".git").isDirectory()).toBe(true);
437437
expect(fs.lstatSync(".gitignore").isFile()).toBe(true);
438+
expect((await execa("git", ["branch", "--show-current"])).stdout).toEqual(
439+
"main"
440+
);
438441
});
439442

440443
it("should not offer to initialize a git repo if it's already inside one", async () => {

packages/wrangler/src/index.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,10 @@ function createCLIParser(argv: string[]) {
444444
yesFlag ||
445445
(await confirm("Would you like to use git to manage this Worker?"));
446446
if (shouldInitGit) {
447-
await execa("git", ["init", "--initial-branch=main"], {
447+
await execa("git", ["init"], {
448+
cwd: creationDirectory,
449+
});
450+
await execa("git", ["branch", "-m", "main"], {
448451
cwd: creationDirectory,
449452
});
450453
await writeFile(

0 commit comments

Comments
 (0)