Skip to content

Commit

Permalink
Git default main branch (#1111)
Browse files Browse the repository at this point in the history
* Git default `main` branch

polish: Default branch when choosing to initialize a git repository will now be `main`.
This is inline with current common industry ethical practices.
See:
- https://sfconservancy.org/news/2020/jun/23/gitbranchname/
- https://github.com/github/renaming
- https://sfconservancy.org/news/2020/jun/23/gitbranchname/

* test: confirmed the default initialized branch is `main` as the "symbolic-ref" "HEAD"
  • Loading branch information
JacobMGEvans authored May 25, 2022
1 parent 515a52f commit 1eaefeb
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
13 changes: 13 additions & 0 deletions .changeset/giant-trees-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"wrangler": patch
---

Git default `main` branch

polish: Default branch when choosing to initialize a git repository will now be `main`.
This is inline with current common industry ethical practices.
See:

- https://sfconservancy.org/news/2020/jun/23/gitbranchname/
- https://github.com/github/renaming
- https://sfconservancy.org/news/2020/jun/23/gitbranchname/
31 changes: 29 additions & 2 deletions packages/wrangler/src/__tests__/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fs from "node:fs";
import * as fsp from "node:fs/promises";
import path from "node:path";
import * as TOML from "@iarna/toml";
import { execa } from "execa";
import { execa, execaSync } from "execa";
import { parseConfigFileTextToJson } from "typescript";
import { version as wranglerVersion } from "../../package.json";
import { getPackageManager } from "../package-manager";
Expand Down Expand Up @@ -412,10 +412,37 @@ describe("init", () => {
`);
});

// I... don't know how to test this lol
it.todo(
"should not offer to initialize a git repo if git is not installed"
);
// I... don't know how to test this lol

it("should initialize git repo with `main` default branch", async () => {
mockConfirm(
{
text: "Would you like to use git to manage this Worker?",
result: true,
},
{
text: "No package.json found. Would you like to create one?",
result: false,
}
);
await runWrangler("init");
expect(std).toMatchInlineSnapshot(`
Object {
"debug": "",
"err": "",
"out": "✨ Created wrangler.toml
✨ Initialized git repository",
"warn": "",
}
`);

expect(execaSync("git", ["symbolic-ref", "HEAD"]).stdout).toEqual(
"refs/heads/main"
);
});
});

describe("package.json", () => {
Expand Down
4 changes: 3 additions & 1 deletion packages/wrangler/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,9 @@ function createCLIParser(argv: string[]) {
yesFlag ||
(await confirm("Would you like to use git to manage this Worker?"));
if (shouldInitGit) {
await execa("git", ["init"], { cwd: creationDirectory });
await execa("git", ["init", "--initial-branch=main"], {
cwd: creationDirectory,
});
await writeFile(
path.join(creationDirectory, ".gitignore"),
readFileSync(path.join(__dirname, "../templates/gitignore"))
Expand Down

0 comments on commit 1eaefeb

Please sign in to comment.