Skip to content

Commit

Permalink
fix: ensure wrangler init works with older versions of git
Browse files Browse the repository at this point in the history
Rather than using the recently added `--initial-branch` option, we now just renamed the initial branch using `git branch -m main`.

Fixes #1168
  • Loading branch information
petebacondarwin committed Jun 9, 2022
1 parent 4e19e9b commit 818c493
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
9 changes: 9 additions & 0 deletions .changeset/tender-chefs-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"wrangler": patch
---

fix: ensure wrangler init works with older versions of git

Rather than using the recently added `--initial-branch` option, we now just renamed the initial branch using `git branch -m main`.

Fixes https://github.com/cloudflare/wrangler2/issues/1168
3 changes: 3 additions & 0 deletions packages/wrangler/src/__tests__/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,9 @@ describe("init", () => {
`);
expect(fs.lstatSync(".git").isDirectory()).toBe(true);
expect(fs.lstatSync(".gitignore").isFile()).toBe(true);
expect((await execa("git", ["branch", "--show-current"])).stdout).toEqual(
"main"
);
});

it("should not offer to initialize a git repo if it's already inside one", async () => {
Expand Down
5 changes: 4 additions & 1 deletion packages/wrangler/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,10 @@ function createCLIParser(argv: string[]) {
yesFlag ||
(await confirm("Would you like to use git to manage this Worker?"));
if (shouldInitGit) {
await execa("git", ["init", "--initial-branch=main"], {
await execa("git", ["init"], {
cwd: creationDirectory,
});
await execa("git", ["branch", "-m", "main"], {
cwd: creationDirectory,
});
await writeFile(
Expand Down

0 comments on commit 818c493

Please sign in to comment.